aspose 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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we view the generated sql using PreparedStatement ?