File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How can we view the generated sql using PreparedStatement ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How can we view the generated sql using PreparedStatement ?" Watch "How can we view the generated sql using PreparedStatement ?" New topic
Author

How can we view the generated sql using PreparedStatement ?

Sreejith kayappuram
Ranch Hand

Joined: Jun 24, 2008
Posts: 35
Hi,
is there any way we can get the SQL query generated with replacing '?' with its corresponding 'value'.
eg.
PreparedStatement stmt = conn.prepareStatement("select id, name from users where id = ?");
stmt.setInt(1);

i would like to get an output in console like " select id, name from users where id = 1 "

I have heard like iPreparedStatement or something for this purpose only. I am not sure about that.

is there any way ?


Thanks
Sreejith
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can use a tool like p6spy for this.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sreejith kayappuram
Ranch Hand

Joined: Jun 24, 2008
Posts: 35
Ok. Thanks for the reply
 
Consider Paul's rocket mass heater.
 
subject: How can we view the generated sql using PreparedStatement ?