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

Re: getUdateCount() vs. RETURNING clause

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: getUdateCount() vs. RETURNING clause
Date: 2009-11-25 07:31:37
Message-ID: heimgq$sdo$ (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Oliver Jowett, 25.11.2009 01:40:
> Thomas Kellerer wrote:
>> boolean hasResult = pstmt.execute();
>> if (hasResult) {
>>  ResultSet rs = pstmt.getResultSet();
>>  if (rs != null && {
>>    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.

Hmm, my understand was a bit different. 

The Javadocs simply say

There are no more results when the following is true:
((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))

It doesn't state that they are mutually exclusive. And for me it seemed to imply that I can call getMoreResults() and getUpdateCount() in a loop in order to process everything that is returned.

Additionally the Javadocs for getUpdateCount() says:

"Gets the *current* result as an update count" and ".. if there are no more results it returns -1"

The word "current" here also let me to believe I can call those methods multiple times. 


In response to


pgsql-jdbc by date

Next:From: Oliver JowettDate: 2009-11-25 11:13:40
Subject: Re: getUdateCount() vs. RETURNING clause
Previous:From: Oliver JowettDate: 2009-11-25 00:40:30
Subject: Re: getUdateCount() vs. RETURNING clause

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