| Author |
JDBC - Using variable in sql query?
|
aseem agarwal
Greenhorn
Joined: Oct 17, 2009
Posts: 9
|
|
I want to execute something like this...
String s=new String("aa");
query="select * from users where id="+s;
Basically i want to put a variable in where condition and the above statement is not working...Can anyone help me with this....
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
You can use a PreparedStatement.
See Java JDBC Tutorial
You put a '?' in your sql statement where the variable has to be places.
You later on bind the variable by calling a PreparedStatement.setXXX() method.
Regards, Jan
|
OCUP UML fundamental
ITIL foundation
|
 |
aseem agarwal
Greenhorn
Joined: Oct 17, 2009
Posts: 9
|
|
|
ya got it....thanks
|
 |
 |
|
|
subject: JDBC - Using variable in sql query?
|
|
|