pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hugo Sacramento <hugo_sacramento@yahoo.com.br>
To: pgsql-jdbc@postgresql.org
Subject: Re: Retrieve Query
Date: Thu, 02 Mar 2006 21:30:24 -0300
Message-ID: <44078E20.3010703@yahoo.com.br> (raw)
In-Reply-To: <Pine.LNX.4.44.0602271348500.13368-100000@matrix.gatewaynet.com>
References: <Pine.LNX.4.44.0602271348500.13368-100000@matrix.gatewaynet.com>

I got jdbc source code and make it with follow change:

org.postgresql.jdbc3.Jdbc3PreparedStatement.java:

    public String toString() {
        return preparedQuery.toString(preparedParameters);
    }

Works fine.


Achilleus Mantzios escreveu:
> 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.jboss.pool.wrappedStatement@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
>>
>>     
>
>   


		
_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora!
http://br.acesso.yahoo.com



view thread (4+ messages)

Message-ID: <44078E20.3010703@yahoo.com.br>
Permalink:  ../44078E20.3010703@yahoo.com.br/
Also on:    postgresql.org/message-id/44078E20.3010703@yahoo.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hugo_sacramento@yahoo.com.br
  Subject: Re: Retrieve Query
  In-Reply-To: <44078E20.3010703@yahoo.com.br>
  References: <Pine.LNX.4.44.0602271348500.13368-100000@matrix.gatewaynet.com> <44078E20.3010703@yahoo.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox