pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: getUdateCount() vs. RETURNING clause
Date: Thu, 26 Nov 2009 02:14:24 +1300
Message-ID: <4B0D2DB0.8020707@opencloud.com> (raw)
In-Reply-To: <hej80d$h7p$1@ger.gmane.org>
References: <hegh0m$j0f$1@ger.gmane.org>
	<4B0C7CFE.50106@opencloud.com>
	<heimgq$sdo$1@ger.gmane.org>
	<4B0D1164.1060006@opencloud.com>
	<hej5r1$aqs$1@ger.gmane.org>
	<4B0D2014.3060703@opencloud.com>
	<hej80d$h7p$1@ger.gmane.org>

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



view thread (10+ messages)  latest in thread

Message-ID: <4B0D2DB0.8020707@opencloud.com>
Permalink:  ../4B0D2DB0.8020707@opencloud.com/
Also on:    postgresql.org/message-id/4B0D2DB0.8020707@opencloud.com

 · 

reply

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: oliver@opencloud.com, spam_eater@gmx.net
  Subject: Re: getUdateCount() vs. RETURNING clause
  In-Reply-To: <4B0D2DB0.8020707@opencloud.com>
  References: <hegh0m$j0f$1@ger.gmane.org> <4B0C7CFE.50106@opencloud.com> <heimgq$sdo$1@ger.gmane.org> <4B0D1164.1060006@opencloud.com> <hej5r1$aqs$1@ger.gmane.org> <4B0D2014.3060703@opencloud.com> <hej80d$h7p$1@ger.gmane.org> <4B0D2DB0.8020707@opencloud.com>

* 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