Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple SQL Query Problem?

Status
Not open for further replies.

Vaastav

Programmer
Nov 6, 2002
5
GB
Hi how do I embed a variable in a sql statement in a Java bean. I am trying reference a vaule from my jsp which is stored in the variable argshowcourse in my java bean. Is this the right way to do it?

String sqlQuery = "SELECT * from modules WHERE 'argShowCourse' = 'O';
 
If the variable - argShowCourse contains the name of a column in your table, you would code the following:

String sqlQuery = "SELECT * from modules WHERE " + argShowCourse + " = 'O'";

If the variable - argShowCource contains the value you want to search for, you would code the following:

String sqlQuery = "SELECT * from modules WHERE COLUMNNAME = '" + argShowCourse + "'";

If the query is going to be used multiple times (with different values in the argShowCourse variable, you may be better off using a PreparedStatement to handle your query.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top