Re: Getting query SQL from a JDBC PreparedStatement



Larry Coon wrote:
Using Sybase JConnect's implementation of JDBC in Java 1.5.

For logging/debug purposes, I want to get the SQL query text from
a PreparedStatement (which is a SybPreparedStatement in this
implementation). Something like:

String query = "select xxx from mytable where aaa = ? and bbb = ?";

SybPreparedStatement s = (SybPreparedStatement)
connection.prepareStatement(query);

s.setString(1, "sarg1");
s.setString(2, "sarg2");

------

At this point I want to get the query text, i.e.:

select xxx from mytable where aaa = "sarg1" and bbb = "sarg2"

From the prepared statement. toString() doesn't return the query,
it returns a string like:

com.sybase.jdbc2.jdbc.SybPreparedStatement@1f630dc

And I see no other methods that return a String. What am I missing
here?


This maybe a backwards way of doing it. I would use a debugger and step thru the instructions to find SybPreparedStatement and look it its content.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
.



Relevant Pages

  • Re: Getting query SQL from a JDBC PreparedStatement
    ... I want to get the SQL query text from ... a PreparedStatement (which is a SybPreparedStatement in this ... connection when asking for a PreparedStatement. ...
    (comp.lang.java.databases)
  • Re: PrepareStatement
    ... PreparedStatement ps = ... how can i get sql query that is formed by PrepareStatement? ... The only query string available is the one referenced via your 'query' variable. ... It's a bad idea to embed implementation details in variable names. ...
    (comp.lang.java.programmer)
  • Getting query SQL from a JDBC PreparedStatement
    ... For logging/debug purposes, I want to get the SQL query text from ... a PreparedStatement (which is a SybPreparedStatement in this ...
    (comp.lang.java.databases)