This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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

Displaying the Query Content of PreparedStatement

Jinto Lonappan

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

map.put(preparedStatement, sqlString);

Then you look up the sqlString by passing the preparedStatement back to the map when it is needed. - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jinto Lonappan

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

Joined: Oct 14, 2005
Posts: 19973

"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.
I agree. Here's the link:
subject: Displaying the Query Content of PreparedStatement
It's not a secret anymore!