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 501CF9FA5B5 for ; Mon, 5 Jun 2006 14:22:13 -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 52820-04 for ; Mon, 5 Jun 2006 14:21:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.diuno.com.br (mail.diuno.com.br [200.175.102.226]) by postgresql.org (Postfix) with ESMTP id 01ACA9FA12F for ; Mon, 5 Jun 2006 14:21:57 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: RES: PGJDBC 8 transaction problem Date: Mon, 5 Jun 2006 14:20:46 -0300 Message-ID: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEF@moscou.diuno.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [JDBC] PGJDBC 8 transaction problem Thread-Index: AcaIo4A/CuOS5NHGTSSu29JS53rHpwAIGMkw From: "Rodrigo Willian Bonatto" To: "Oliver Jowett" Cc: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/18 X-Sequence-Number: 15298 Hi Oliver and Dave, I agree with you. I could use conn.commit(), but I have a particular environment here and I'll try to explain. My application use XML in my business tier to create and validate my business rules. My application use the connection provided by a data source Application Server and I use my own XML tags, like to get some information from database to be used in my business rules. Some times I need to update some records and use these data in my business rules and I need to this using my own XML tags. In some cases I use BEGIN with COMMIT in the body of my own XML tag to perform some updates and queries without java code.=20 Using BEGIN and COMMIT with PGJDBC 7.4 works perfectly but not with version 8.x. I could use another XML tag to perform update separately from another SQL queries, but I would like to know if PGJDBC 8 supports BEGIN and COMMIT in a single statement. Regards, Rodrigo -----Mensagem original----- De: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] Em nome de Oliver Jowett Enviada em: segunda-feira, 5 de junho de 2006 10:25 Para: Rodrigo Willian Bonatto Cc: pgsql-jdbc@postgresql.org Assunto: Re: [JDBC] PGJDBC 8 transaction problem Rodrigo Willian Bonatto wrote: > query.append("BEGIN;"); > query.append("update employee set age =3D 28 where age =3D 27;"); > query.append("COMMIT;"); > query.append("select name from employee where age =3D 28"); > ResultSet rs =3D stmt.executeQuery(query.toString()); >=20 > Here the resultset will return "John", but if I use PGJDBC driver=20 > version 8 or greater, the statement return any result. The more recent drivers implement support for returning multiple=20 resultsets from a query correctly, which older drivers didn't do. Your=20 Statement will actually have four results associated with it -- one for=20 each of BEGIN, UPDATE, COMMIT, SELECT. I would expect executeQuery() to=20 throw an exception because the query returned something other than a=20 single resultset. You will need to use Statement.execute() / Statement.getMoreResults() /=20 Statement.getResultSet() to step to the 4th result and retrieve the=20 SELECT's results (you could also get at the UPDATE's update count in a=20 similar way). Also, you should avoid explicit BEGIN/COMMIT statements if you can --=20 Connection.setAutocommit() / Connection.commit() is the recommended way=20 to manage transaction boundaries. -O ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org