Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update D/b with Java variable

 
Kashyap Hosdurga
Ranch Hand
Posts: 92
  • 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: 92
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic