Re: Retrieve Query

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Markus Schaber <schabi(at)logix-tt(dot)com>
Cc: Hugo Sacramento <hugo_sacramento(at)yahoo(dot)com(dot)br>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Retrieve Query
Date: 2006-02-27 11:55:31
Message-ID: Pine.LNX.4.44.0602271348500.13368-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

O Markus Schaber έγραψε στις Feb 27, 2006 :

> Hi, Hugo,
>
> Hugo Sacramento wrote:
> > How do I to retrieve the string query prepared by a PreparedStatement??
>
> > -------------
> > PreparedStatement stmt = con.prepareStatement("select * from abc where
> > x=?");
> > stmt.setString(1, x);
> > System.out.println("My Prepared Query:" + stmt.toString());
> > ------------
> >
> > but it don't work.
>
> There are at least two potential problems:
>
> - The statement is prepared server-side, and the parameters are sent
> separately (binding). Only the server has the "real" representation of
> the complete statement. So the prepared statement can only give an
> approximation, which is what pgjdbc does.
>
> - Most connection pooling and datasource mechanisms (e. G. in jboss)
> wrap your connection and all other classes (including the statement),
> but don't delegate the toString() method, so you'll only get something
> like "org(dot)jboss(dot)pool(dot)wrappedStatement(at)4711".

In jboss there is getUnderlyingStatement() method
so you could

PreparedStatement st=...
.....
org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement jst =
(org.jboss.resource.adapter.jdbc.local.LocalPreparedStatement) st;

org.postgresql.jdbc3.Jdbc3PreparedStatement pst =
(org.postgresql.jdbc3.Jdbc3PreparedStatement) jst.getUnderlyingStatement();

System.out.println(pst.toString());

>
> HTH,
> Markus
>

--
-Achilleus

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2006-02-27 22:08:48 Re: postgres PreparedStatement commented ? problem PSQLException:
Previous Message Markus Schaber 2006-02-27 10:38:26 Re: Retrieve Query