Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id F38141337BA8 for ; Fri, 18 Mar 2011 19:52:36 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 24823-05 for ; Fri, 18 Mar 2011 22:52:30 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id ADC8C1337BA3 for ; Fri, 18 Mar 2011 19:52:29 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id p2IMqTn7039939 for ; Fri, 18 Mar 2011 19:52:29 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id p2IMlfTr088848 for pgsql-jdbc@postgresql.org; Fri, 18 Mar 2011 19:47:41 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: Problem with executeBatch and "A result was returned when none was expected" Date: Fri, 18 Mar 2011 18:47:59 -0400 Organization: albasani.net Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: news.albasani.net; logging-data="htrPkx9ufbS+B+BgatrgJh+dTm4iXE+sUUFiFmgl4OKwypsPTOHqugBxF6MZJ/frnUMnAFrOWr0EGFj9lJEt69IFBt/xSyHhHmatT3PfBRuiTlqJ6Wm/ZKSEubxexQRg"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 In-Reply-To: Cancel-Lock: sha1:PqaCaHTud1qTqk/Ql1XYm4Pmf68= To: pgsql-jdbc@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/28 X-Sequence-Number: 21583 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.