X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 806F79FA2DB for ; Mon, 5 Jun 2006 10:25:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 17744-02 for ; Mon, 5 Jun 2006 10:25:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id EFD929FA111 for ; Mon, 5 Jun 2006 10:25:39 -0300 (ADT) Received: from 221x253x225x162.ap221.ftth.ucom.ne.jp ([221.253.225.162] helo=[192.168.1.171]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1FnF5D-0007DE-DZ; Tue, 06 Jun 2006 01:25:30 +1200 Message-ID: <448430B2.6020602@opencloud.com> Date: Mon, 05 Jun 2006 22:25:06 +0900 From: Oliver Jowett User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Rodrigo Willian Bonatto CC: pgsql-jdbc@postgresql.org Subject: Re: PGJDBC 8 transaction problem References: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEC@moscou.diuno.net> In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEC@moscou.diuno.net> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/17 X-Sequence-Number: 15297 Rodrigo Willian Bonatto wrote: > query.append("BEGIN;"); > query.append("update employee set age = 28 where age = 27;"); > query.append("COMMIT;"); > query.append("select name from employee where age = 28"); > ResultSet rs = stmt.executeQuery(query.toString()); > > Here the resultset will return “John”, but if I use PGJDBC driver > version 8 or greater, the statement return any result. The more recent drivers implement support for returning multiple resultsets from a query correctly, which older drivers didn't do. Your Statement will actually have four results associated with it -- one for each of BEGIN, UPDATE, COMMIT, SELECT. I would expect executeQuery() to throw an exception because the query returned something other than a single resultset. You will need to use Statement.execute() / Statement.getMoreResults() / Statement.getResultSet() to step to the 4th result and retrieve the SELECT's results (you could also get at the UPDATE's update count in a similar way). Also, you should avoid explicit BEGIN/COMMIT statements if you can -- Connection.setAutocommit() / Connection.commit() is the recommended way to manage transaction boundaries. -O