The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
September 2001



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.


Java Reflection might help you...

Posted by Anil S. Karkera on September 27, 2001 at 1:02 PM

I don't quite understand what you're attempting to do however I
think you might want to look into using reflection in your
code, if you can email or post a code snippet to support your
question we might be able to help you.


> 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

> 10/11/01 13:49:55

> ---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...


  • SQL logging John Senford September 28, 2001 at 4:19 AM (0)

Sponsored Links

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