This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

building a dynamic Query String

 
prabhu kandanur
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

building a dynamic Query String "using java code examples"
where can i get
-prabhu
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you perhaps mean a PreparedStatement? For example:

String query = "SELECT * FROM sometable WHERE sometable.somefield = ?";
PreparedStatement stmt = conn.prepareStatement(query);

The question mark represents a value that is set at runtime. You set the value with a call to a setter method on the Statement object:

// Could be setInt(), setDate(), setBoolean(), etc.
stmt.setString( 1, getValueForSQL() );
rs = stmt.executeQuery();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic