This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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.........
 
Don't get me started about those stupid light bulbs.
 
subject: equalizing a variable in an sql statement