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?

Nothing. There is no standard JDBC or sybase-specific
method or variable which exposes the SQL you gave the
connection when asking for a PreparedStatement. The
statement certainly does have a version of the string,
possibly modified for the JDBC SQL escapes, but you
would have to decompile, alter, and recompile, and run
your modified driver to be able to get it programmatically.
Joe Weinstein at BEA Systems

.



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 ... And I see no other methods that return a String. ...
    (comp.lang.java.databases)
  • Re: DBMS and lisp, etc.
    ... Naively implemented with SQL, again for 10 ... (1 query for the initial orders, 1 query for each order for its ... soon as you upgrade to the SQL database. ... (eq (order-customer orderA) ...
    (comp.lang.lisp)
  • Re: Populating a list -- table structure?
    ... I had made a report already and figured out about adding the ... your responce below, but thanks to your help with SQL, I was able to get the ... It takes a summary from a select query and gives the ... KitID, long integer ...
    (microsoft.public.access.forms)
  • How do I do Paging through a large dataset via Stored Procedures
    ... Paging by dynamically altering the SQL Query ... Create stored procedures ... SELECT * FROM STUDENTS ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Populating a list -- learning Access
    ... It is kinda funny -- I started using databases in the early 80's with dBase and, for years, never knew that I knew SQL! ... If you are on a form or report, the most important property is the NAME, because that is how you refer to it in code. ... I don't mean to skip your responce below, but thanks to your help with SQL, I was able to get the query to pull the info the way I needed. ... Queries (just shows the QBE grid for convenience -- ...
    (microsoft.public.access.forms)