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: Wed, 25 Nov 2009 13:40:30 +1300
Message-ID: <4B0C7CFE.50106@opencloud.com> (raw)
In-Reply-To: <hegh0m$j0f$1@ger.gmane.org>
References: <hegh0m$j0f$1@ger.gmane.org>

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




view thread (10+ messages)  latest in thread

Message-ID: <4B0C7CFE.50106@opencloud.com>
Permalink:  ../4B0C7CFE.50106@opencloud.com/
Also on:    postgresql.org/message-id/4B0C7CFE.50106@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: <4B0C7CFE.50106@opencloud.com>
  References: <hegh0m$j0f$1@ger.gmane.org> <4B0C7CFE.50106@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