Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D8C5063328E for ; Wed, 25 Nov 2009 09:14:40 -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 10612-05 for ; Wed, 25 Nov 2009 13:14:05 +0000 (UTC) X-Greylist: from auto-whitelisted 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 A3F77633288 for ; Wed, 25 Nov 2009 09:14:29 -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 1NDHhQ-0006tJ-L0; Thu, 26 Nov 2009 02:14:24 +1300 Message-ID: <4B0D2DB0.8020707@opencloud.com> Date: Thu, 26 Nov 2009 02:14:24 +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: <4B0C7CFE.50106@opencloud.com> <4B0D1164.1060006@opencloud.com> <4B0D2014.3060703@opencloud.com> 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.227 tagged_above=-10 required=5 tests=AWL=0.372, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/29 X-Sequence-Number: 20076 Thomas Kellerer wrote: > Back to my original question then: why doesn't the Postgres driver > return 1 as the updateCount in this situation? > I only get a single result set (which is correct) but never a 1 as the > update count. Back to my original answer then ;-) Quoting your original code: > PreparedStatement pstmt = con.prepareStatement(UPDATE_SQL); // the statement from above > pstmt.setInt(1, 42); > 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); You never call getMoreResults(), so you are only looking at a single result, which is either a resultset or an update count, never both. -O