aspose file tools*
The moose likes JDBC and the fly likes Get SQL value out of PreparedStatement - Any API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get SQL value out of PreparedStatement - Any API" Watch "Get SQL value out of PreparedStatement - Any API" New topic
Author

Get SQL value out of PreparedStatement - Any API

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
Is there a way to get the SQL out of a PreparedStatement?

PreparedStatement prepStmnt = conn.prepareStatement("select * from table");

Is there any API that will let me extract the sql that is the inherent part of prepStmnt.

Goal is to get "select * from table" value out of prepStmnt variable.
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
Not in standard JDBC.

Some drivers may have vendor-supplied add-ons to do that.

Some people create "wrapper" classes that will store the SQL and the bind variable values and give them up on request.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If you search this forum for 'DebuggableStatement' it will give you one option of that type, and links to a few more.

Dave
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Get SQL value out of PreparedStatement - Any API