wood burning stoves 2.0*
The moose likes JDBC and the fly likes Update D/b with Java variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Update D/b with Java variable" Watch "Update D/b with Java variable" New topic

Update D/b with Java variable

Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 87
I am new to JDBC.
I have a select query and I need to use a Java variable in where condition. I am trying to use it directly in the query. Can anyone please let me know what needs to be done to use a variable declared in the function.

eg code

int x = 10;
ResultSet rs = stmt.executeQuery("select * from Table where value=x") ;

What should I do to use variable x in the SQL stmt.
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
There are several ways but the best way for about half-a-dozen different reasons is to use a PreparedStatement.

Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 87
Thank you stu
Also can you please let me know where I can find more details about JDBC.
I tried google
Any book about JDBC will be helpful
Masoud Kalali
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

you can find more details on jdbc at
http://www.javaolympus.com/index.jsp , indeed you will find resource about all java APIs there

Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
I agree. Here's the link: http://aspose.com/file-tools
subject: Update D/b with Java variable
Similar Threads
Select Changes Behaviour Because Of Round Brackets
In clause in oracle
date problem
query select where
Can anyone use IN clause of query with preparedStatement like below?