Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying the Query Content of PreparedStatement

 
Jinto Lonappan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I display the Query with all the ? replaced with its original value in a PreparedStatement?

Thanks in advance..
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surprisingly I don't think you can.

Recently I implemented a performance monitoring driver (www.jamonapi.com) that needed to see what sql was associated with a PreparedStatement and I kept the info in a WeakHashMap to do that. WeakHashMap contents are garbage collected when they go out of scope. Very cool.

i.e.
map.put(preparedStatement, sqlString);

Then you look up the sqlString by passing the preparedStatement back to the map when it is needed.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34672
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jinto,
Take a look at the FAQ entry titled "How do I view the actual SQL that a PreparedStatement is sending to the database?"
 
Jinto Lonappan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve and Jeanne..
 
Paul Clapham
Sheriff
Posts: 21133
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Jinto KL", I can see you have been at the JavaRanch for a while. But it looks like nobody mentioned that we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed. ("KL" is not a last name.)

Please edit your profile and correct your display name since accounts with incorrect display names will be deleted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic