File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes My new favourite thing: DebuggableStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "My new favourite thing: DebuggableStatement " Watch "My new favourite thing: DebuggableStatement " New topic

My new favourite thing: DebuggableStatement

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I use PreparedStatements a lot, but the biggest thing that annoys me about them is that you can't print them out after you have set the values. A PreparedSatement has no meaningful 'toString' implementation.
Until this.
This article from JavaWorld provides a simple way to add a wrapper to a PreparedStatement so that you can print the equivalent SQL and see what the current state is.
I'm still playing with it, but it's much better than not having any way of seeing inside a PreparedStatement.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

What, haven't you heard about P6Spy?
[Or is that not suitable for you?]
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
I prefer the solution that just means changing the driver name to enable statement/timing logging rather than rewritting code. (i.e. P6spy)
That said, you might as well just use the oracle tracing utilities.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

We plugged the DebuggableStatement into our persistence framework so its use is defined by the debugging property. ie when we are in debug mode, it also uses the DebuggableStatement to log statements, otherwise it uses PreparedStateents directly.
I'm still not convinced the DebuggableStatement behaves exactly the same as a PreparedStatment, so I'm being wary, but it has definitely made the last two days easier for me.
I agree. Here's the link:
subject: My new favourite thing: DebuggableStatement
It's not a secret anymore!