pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Rodrigo Willian Bonatto <bonatto@diuno.com.br>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: PGJDBC 8 transaction problem
Date: Mon, 05 Jun 2006 22:25:06 +0900
Message-ID: <448430B2.6020602@opencloud.com> (raw)
In-Reply-To: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEC@moscou.diuno.net>
References: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEC@moscou.diuno.net>

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



view thread (3+ messages)

Message-ID: <448430B2.6020602@opencloud.com>
Permalink:  ../448430B2.6020602@opencloud.com/
Also on:    postgresql.org/message-id/448430B2.6020602@opencloud.com

 · 

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: oliver@opencloud.com, bonatto@diuno.com.br
  Subject: Re: PGJDBC 8 transaction problem
  In-Reply-To: <448430B2.6020602@opencloud.com>
  References: <54CC7CADE26E884EB2BCEC863F5C1F7001012FEC@moscou.diuno.net> <448430B2.6020602@opencloud.com>

* 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