Skip site navigation (1) Skip section navigation (2)

Re: getUdateCount() vs. RETURNING clause

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: getUdateCount() vs. RETURNING clause
Date: 2009-11-25 00:40:30
Message-ID: 4B0C7CFE.50106@opencloud.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
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


In response to

Responses

pgsql-jdbc by date

Next:From: Thomas KellererDate: 2009-11-25 07:31:37
Subject: Re: getUdateCount() vs. RETURNING clause
Previous:From: Thomas KellererDate: 2009-11-24 11:45:26
Subject: getUdateCount() vs. RETURNING clause

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group