Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes JDBC and Relational Databases and the fly likes Displaying the Query Content of PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Displaying the Query Content of PreparedStatement" Watch "Displaying the Query Content of PreparedStatement" New topic
Author

Displaying the Query Content of PreparedStatement

Jinto Lonappan
Greenhorn

Joined: Mar 13, 2006
Posts: 20
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

Joined: Jun 26, 2002
Posts: 862
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.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31634
    
189

Jinto,
Take a look at the FAQ entry titled "How do I view the actual SQL that a PreparedStatement is sending to the database?"


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jinto Lonappan
Greenhorn

Joined: Mar 13, 2006
Posts: 20
Thanks Steve and Jeanne..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 19357
    
  10

"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.
 
Consider Paul's rocket mass heater.
 
subject: Displaying the Query Content of PreparedStatement