6 Replies Latest reply on Jun 7, 2005 9:08 AM by Balamaci Serban

    getting the SQL out of PreparedStatement

    Balamaci Serban Newbie

      I was wondering, if one can get the SQL out of a PreparedStatement.
      For example the code in

      public class TestClass {
      public void aMethod () {
      PreparedStatement sql=con.prepareStatement("INSERT
      INTO person(id,adress,age) VALUES(?,?,?,?)");
      sql.setInt(1,22);
      sql.setString(2,?Str. .....?);
      sql.setInt(3,24);
      sql.executeUpdate();
      }
      }
      We could write an interceptor, intercept prepareStatement and get the parameter, but the SQL String has those nasty ? ? ? in it.

      Next we have another interceptor intercept the ..PreparedStatement->set*(..) but how would i be able to get the info extracted with the first interceptor(the SQL String with ? ? ? in it), if only i could get, that then i would use a regular expresion to parse it and add the info of that perticular set* method instead of the ?
      and finally at executeUpdate() i would just have the plain clear as day SQL.

      Metadata to pass the data from one Interceptor to the other is out of the question i guess cause i belive that's for chains of interceptors, right?
      How about we dinamicaly add a field to the TestClass and put the partial result of all the calls in there. Could we do that?

      Is it possible to make it work. Any ideas?