my dog learned polymorphism*
The moose likes Java in General and the fly likes equalizing a variable in an sql statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "equalizing a variable in an sql statement" Watch "equalizing a variable in an sql statement" New topic
Author

equalizing a variable in an sql statement

Keshini Weerasuriya
Greenhorn

Joined: Jan 08, 2006
Posts: 24
Hi...

I'm trying to equal an ID which is taken as user input in an sql staement as below..

int answer = Integer.parseInt(mainMenu.client);
ResultSet rs = st.executeQuery("select * from Client where CliId = answer ");

Give the error, java.sql.SQLException: ORA-00904: invalid column name
Pls help.. Tnx..
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
It looks like the column name you listed was not found in the table. I'm not sure, but it may be case sensitive.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Also note that you have included the 'answer' variable with in the quotes. So the query that will be executed in the database will be


The proper way to build the query is


Another way is to use a PreparedStatement


Mani
Quaerendo Invenietis
Keshini Weerasuriya
Greenhorn

Joined: Jan 08, 2006
Posts: 24
Tnx Mani Ram.. Your method works.........
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: equalizing a variable in an sql statement
 
Similar Threads
Need to perform wildcard search
request.parameter
Difference between Statement/Prepared statement?
HFEJB page 435
jstl sql action