This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Update D/b with Java variable" Watch "Update D/b with Java variable" New topic
Author

Update D/b with Java variable

Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 83
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: 83
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
Author
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
query select where
Select Changes Behaviour Because Of Round Brackets
In clause in oracle
Can anyone use IN clause of query with preparedStatement like below?
date problem