Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can we view the generated sql using PreparedStatement ?

 
Sreejith kayappuram
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a tool like p6spy for this.
 
Sreejith kayappuram
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks for the reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic