From: Lew <noone@lewscanon.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Problem with executeBatch and "A result was returned when none was expected"
Date: Fri, 18 Mar 2011 18:47:59 -0400
Message-ID: <im0nee$n5q$1@news.albasani.net> (raw)
In-Reply-To: <AANLkTinRJj_WpwzAbfR4yqbd68=rUs2AB_4t0ELJjsxP@mail.gmail.com>
References: <C9A5DB9A.5002%pico303@gmail.com>
<AANLkTinRJj_WpwzAbfR4yqbd68=rUs2AB_4t0ELJjsxP@mail.gmail.com>
Oliver Jowett wrote:
> Sean Bowman wrote:
>> I've been trying to batch create a bunch of records using stored procedures and
>> the executeBatch() method (so I can get back the generated PKID's) with no luck. ...
>> When I try to call executeBatch, I get a BatchUpdateException with the message:
>> "A result was returned when none was expected".
This is the documented result when a statement tries to create a result set:
"Throws BatchUpdateException (a subclass of SQLException) if one of the
commands sent to the database fails to execute properly or attempts to return
a result set."
...
>> Any suggestions or pointing out my code flaws would be most appreciated. Or
>> does executeBatch just not work? I've been battling this issue most of the
>> day and I'm just about at my wits' end. Should I just give up and switch to
>> calling execute() one at a time? Seems far less efficient, but at least it
>> seems to work.
>
> You are correct, generated keys don't work with executeBatch() yet.
> (There was another thread about this a couple of days ago)
How would you retrieve the result if 'executeBatch()' did what you're asking?
There's nothing in the documentation for 'Statement#getGeneratedKeys()' that
indicates a need for a 'RETURNING' clause in the 'INSERT'.
As near as I can tell from the API docs, the behavior you experienced is
required. Postgres tells us about RETURNING that:
"If the INSERT command contains a RETURNING clause, the result will be similar
to that of a SELECT statement containing the columns and values defined in the
RETURNING list, computed over the row(s) inserted by the command."
http://www.postgresql.org/docs/9.0/interactive/sql-insert.html
A SELECT would return a 'ResultSet' through JDBC, thus the API requires your
statement to throw the exception that you got.
--
Lew
Honi soit qui mal y pense.
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: noone@lewscanon.com
Subject: Re: Problem with executeBatch and "A result was returned when none was expected"
In-Reply-To: <im0nee$n5q$1@news.albasani.net>
References: <C9A5DB9A.5002%pico303@gmail.com> <AANLkTinRJj_WpwzAbfR4yqbd68=rUs2AB_4t0ELJjsxP@mail.gmail.com> <im0nee$n5q$1@news.albasani.net>
* 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