uNConVeNtiOnAL (
[email protected]) wrote:
: I have a PreparedStatement that I want to send to system.out.println
: to see exactly the sql that is being sent to the db - printing
: PreparedStatement.toString() just gives the object reference - does
: anyone know how to divulge the string realization of the
: PreparedStatement being sent to the db ??
Usually you can not do that.
Also, if you use prepared statements you usually have a few '?' in the
query string, when debugging/tracing sql you probably want to know what
each of the ? was for each execute.
To achieve this for myself (at work, so I can't share) was to write a
proxy for Connection that returned my own LogStatements/
LogPreparedStatements/LogCallableStatements instead of the thing
returned from the contained database connection. This made it easy to
get logging with full SQL and parameters. Very nice to have when the
system builds lots of queries. (Logging is basically a no-op if noone
is listening of course).
When I did this I also added some code that finds
(callable|prepared)statements that are not closed. Forgetting to close
thoose when the database is an Oracle is not a good idea. Oracle
statemens are never closed, not even in finilize (postgresql seems to
close on finilize). This means that not closing a statement => lots of
open cursors => db will not accept any more statements...
Building something like this is easy. The interfaces are big so it
takes some time, kinda booring actually.
Have fun.
/robo