permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes building a dynamic Query String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "building a dynamic Query String" Watch "building a dynamic Query String" New topic

building a dynamic Query String

prabhu kandanur
Ranch Hand

Joined: Oct 18, 2003
Posts: 34

building a dynamic Query String "using java code examples"
where can i get
M. Gagnon
Ranch Hand

Joined: Feb 18, 2004
Posts: 68
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();
I agree. Here's the link:
subject: building a dynamic Query String
It's not a secret anymore!