The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

SQL Statement Logging

Posted by John Senford on September 27, 2001 at 8:45 AM

I want to create logs of all sql statements being sent to a database.
There is no simple method (e.g. toString(), or toSQL()) provided by the Statement, PreparedStatment, and CallableStatement interfaces therefore I have chosen to create wrapper classes which contain a single Statement/Prepared.../Callable... object and intercept all 'sql string building' operations so as to manually maintain my own copy of the SQL string being used.

However, there is a major flaw in this plan when it comes to the parameter setting of a PreparedStatement. A long list of methods are provided to setting every possible data type and known object type. The simple data types are easy to 'stringify' and insert to my sql string......but what can I do about the various objects that may be used as parameters???
(e.g. Object, java.sql.Date, java.sql.Time, java.sql.Timestamp etc.)

So we can see, if a using class (that I'm not going to write) wants to use PreparedStatement to carry out the operation then my job of logging their sql statement becomes very difficult when they want to set a Date object (for example) as one of the parameters in the sql string.

How do I generate a (simple) log statment for that?!?!?!

by what mechanism could I link a parameter in a simple textual log string to an Object?


example log file:

---START---
10/11/01 13:47:32
SELECT * FROM Book

10/11/01 13:49:55
SELECT BookID FROM Book WHERE Name=?

---END---

now how could I go about linking the parameter for the Name field to an object (let's pretend some complex Java class is used as the data type for the Name field)???


Ideally I do not want to have take this linking approach, but there seems to be no alternative (and how do you do it anyway).

any ideas greatly appreciated...

JohnSenford@hotmail.com



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us