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
Posted by John Senford on September 28, 2001 at 4:19 AM
> I don't quite understand what you're attempting to do however I
> think you might want to look into using reflection
no, Reflection is not relevant to what I am doing.
have you ever used JDBC (java.sql package)?
quite simply, I want to create a log file containing operations (sql statments) carried out on a database.
java.sql.Connection conn = getConnection("database name");
java.sql.PreparedStatement statement = conn.prepareStatement("SELECT name FROM Person WHERE age=?");
//set the 1st (and only, incidentally) parameter in the sql code
//to the value "74"
java.sql.ResultSet results = statement.execute()
now in this example a basic sql statement was created that contained parameters.
before sending it to the database this parameter is set to some value using one of the set methods.
here I used the basic data type int (setInt) so my logging mechanism is able to catch the sql statement, plug in the given int and append the resulting string to the log file.
however, and this is where the situation gets very messy, as well as being able to set the parameters within an sql statement to simpple data types, you are also able to set them to ANY kind of object (setObject method).
obviously the database driver handles this request not by simple sending an sql string to the database but by opening some kind of input stream and squiting in details of the object (or something like that).
but my log file can only contain simple text....so if/when somebody tries to send a statement to the database which has one of it's parameters assigns as an Object, what should my logger do about it??
how can I make a log of what is happening in this case?
somehow I will have to store details about the Object which has been set as the value of the parameter...but how?
any ideas recieved gratefully