X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 8D2039DC9DD for ; Mon, 27 Feb 2006 06:51:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98327-08 for ; Mon, 27 Feb 2006 06:51:26 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by postgresql.org (Postfix) with ESMTP id 22BEA9DC825 for ; Mon, 27 Feb 2006 06:51:21 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id k1RBtbOp013424; Mon, 27 Feb 2006 13:55:37 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id k1RBtVUi013418; Mon, 27 Feb 2006 13:55:31 +0200 Date: Mon, 27 Feb 2006 13:55:31 +0200 (EET) From: Achilleus Mantzios To: Markus Schaber cc: Hugo Sacramento , Subject: Re: Retrieve Query In-Reply-To: <4402D6A2.4080200@logix-tt.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.112 required=5 tests=[AWL=0.112] X-Spam-Score: 0.112 X-Spam-Level: X-Archive-Number: 200602/172 X-Sequence-Number: 14769 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 > -- -Achilleus