Re: BUG #1640: Using JDBC, multiple statements do not return

From: Kris Jurka <books(at)ejurka(dot)com>
To: Kevin Self <kself(at)micromedia(dot)ca>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1640: Using JDBC, multiple statements do not return
Date: 2005-04-30 05:59:26
Message-ID: Pine.BSO.4.56.0504300055400.29877@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 29 Apr 2005, Kevin Self wrote:

> Bug reference: 1640
> PostgreSQL version: 8.0.2
> Description: Using JDBC, multiple statements do not return results if
> select follows insert,delete or update
>
> When attempting to perform a multi-statement command through the JDBC
> Statement.execute() or the Statement.executeQuery() function, the database
> does not return any result set if the select statement follows an insert,
> update or delete. This ability is required for atomic record inserts for
> auto-generated keys that must be returned to the caller, since postgreSQL
> does not support RETURN_GENERATED_KEYS as an option, and calling the
> sequence ahead of time to obtain the value is not possible.

There is no "atomicity" from issuing them in the same query. This is
guaranteed by the sequence for the entire session.

If you do what to do this it should be written as:

Statement.execute("INSERT ...; SELECT currval('myseq')");
Statement.getMoreResults();
ResultSet rs = Statement.getResultSet();

The javadoc for execute() says it should return "true if the first result
is a ResultSet object" the first result is an update count, not a
ResultSet. You need to move to the next result, which is actually a
ResultSet.

Kris Jurka

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jim C. Nasby 2005-04-30 06:13:09 Re: looks like apple fixed /etc/rc
Previous Message Qingqing Zhou 2005-04-30 05:42:46 Re: How to intall postgresql-docs-7.4.6 on win2000?