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 13:14:24
Message-ID: 4B0D2DB0.8020707@opencloud.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

In response to

Responses

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2009-11-25 13:42:27
Subject: Re: getUdateCount() vs. RETURNING clause
Previous:From: Thomas KellererDate: 2009-11-25 12:30:17
Subject: Re: getUdateCount() vs. RETURNING clause

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