Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id C91A06336D3 for ; Tue, 24 Nov 2009 21:13:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 90361-01-9 for ; Wed, 25 Nov 2009 01:13:30 +0000 (UTC) X-Greylist: delayed 00:31:11.106956 by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id B160C6333A9 for ; Tue, 24 Nov 2009 21:11:48 -0400 (AST) Received: from 222-154-85-191.jetstream.xtra.co.nz ([222.154.85.191] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1ND5vr-0001o5-D0; Wed, 25 Nov 2009 13:40:31 +1300 Message-ID: <4B0C7CFE.50106@opencloud.com> Date: Wed, 25 Nov 2009 13:40:30 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Thomas Kellerer CC: pgsql-jdbc@postgresql.org Subject: Re: getUdateCount() vs. RETURNING clause References: In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/23 X-Sequence-Number: 20070 Thomas Kellerer wrote: > boolean hasResult = pstmt.execute(); > > if (hasResult) { > ResultSet rs = pstmt.getResultSet(); > if (rs != null && rs.next()) { > int newId = rs.getInt(1); > System.out.println("newid: " + newId); > } > } > > int affected = pstmt.getUpdateCount(); > System.out.println("affected: " + affected); > > I do see the returned ID from the ResultSet but getUpdateCount() always > returns -1 even though I know that a row was updated. > What am I missing here? Update counts and result sets (for a particular result) are mutually exclusive. If getResultSet() returns non-null then getUpdateCount() must return -1; see the javadoc for those two methods. You probably want to call getMoreResults() in there somewhere to step to the next result. -O