This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "building a dynamic Query String" Watch "building a dynamic Query String" New topic
Author

building a dynamic Query String

prabhu kandanur
Ranch Hand

Joined: Oct 18, 2003
Posts: 34
hi

building a dynamic Query String "using java code examples"
where can i get
-prabhu
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();
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: building a dynamic Query String
 
Similar Threads
Dynamically setting sort direction
Stored Procedure VS normal Query
JPA Query using " where in" and setParameter
Dynamic query creation
Building Dynamic Query in JPA