Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 2DF9F6333E9 for ; Wed, 25 Nov 2009 10:04:12 -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 03208-03 for ; Wed, 25 Nov 2009 14:03:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 54610632F56 for ; Wed, 25 Nov 2009 10:04:01 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.50) id 1NDITO-0005py-PP for pgsql-jdbc@postgresql.org; Wed, 25 Nov 2009 15:03:58 +0100 Received: from 217.110.94.67 ([217.110.94.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Nov 2009 15:03:58 +0100 Received: from spam_eater by 217.110.94.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Nov 2009 15:03:58 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: getUdateCount() vs. RETURNING clause Date: Wed, 25 Nov 2009 15:03:43 +0100 Lines: 35 Message-ID: References: <4B0C7CFE.50106@opencloud.com> <4B0D1164.1060006@opencloud.com> <4B0D2014.3060703@opencloud.com> <4B0D2DB0.8020707@opencloud.com> <4B0D3443.7050902@opencloud.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.67 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <4B0D3443.7050902@opencloud.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.982 tagged_above=-10 required=5 tests=AWL=-0.345, BAYES_20=-0.74, RCVD_NUMERIC_HELO=2.067 X-Spam-Level: X-Archive-Number: 200911/31 X-Sequence-Number: 20078 Oliver Jowett, 25.11.2009 14:42: > You never call getMoreResults(), so you are only looking at a single > result, which is either a resultset or an update count, never both. [...] Hmm, sorry I missed that in my initial email then. I did call getMoreResults() The following still returns false for getMoreResults() PreparedStatement pstmt = con.prepareStatement(update); pstmt.setInt(1, 1); 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); } } boolean more = pstmt.getMoreResults(); // returns false > You may have more success using something like this: > >> PreparedStatement pstmt = con.prepareStatement("UPDATE something with no RETURNING clause", new String[] { "some_column" }); >> int updateCount = pstmt.executeUpdate(); >> ResultSet results = pstmt.getGeneratedKeys(); That indeed works! But I still think the behaviour with getMoreResults() is - at least - confusing ;) Thanks a lot for all your patience! Thomas