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 Displaying the Query Content of PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
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: 852
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29241
    
139

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


[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: 18127
    
    8

"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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Displaying the Query Content of PreparedStatement
 
Similar Threads
nested sql queries using JSP - pls help
In PreparedStatement how it is detected that query has been changed?
How to call stored procedures in ejb2.1?
Difference between Statement/Prepared statement?
storing date in database