Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Update D/b with Java variable

 
Kashyap Hosdurga
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways but the best way for about half-a-dozen different reasons is to use a PreparedStatement.

 
Kashyap Hosdurga
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can find more details on jdbc at
http://www.javaolympus.com/index.jsp , indeed you will find resource about all java APIs there
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!