Re: getUdateCount() vs. RETURNING clause - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: getUdateCount() vs. RETURNING clause
Date
Msg-id 4B0C7CFE.50106@opencloud.com
Whole thread Raw
In response to getUdateCount() vs. RETURNING clause  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: getUdateCount() vs. RETURNING clause  (Thomas Kellerer <spam_eater@gmx.net>)
List 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


pgsql-jdbc by date:

Previous
From: Thomas Kellerer
Date:
Subject: getUdateCount() vs. RETURNING clause
Next
From: Thomas Kellerer
Date:
Subject: Re: getUdateCount() vs. RETURNING clause