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

From Thomas Kellerer
Subject Re: getUdateCount() vs. RETURNING clause
Date
Msg-id hejdfj$3rs$1@ger.gmane.org
Whole thread Raw
In response to Re: getUdateCount() vs. RETURNING clause  (Oliver Jowett <oliver@opencloud.com>)
List pgsql-jdbc
Oliver Jowett, 25.11.2009 14:42:
> You never call getMoreResults(), so you are only looking at a single
> result, which is either a resultset or an update count, never both.
[...]
Hmm, sorry I missed that in my initial email then. I did call getMoreResults()

The following still returns false for getMoreResults()

PreparedStatement pstmt = con.prepareStatement(update);
pstmt.setInt(1, 1);
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);
  }
}
boolean more = pstmt.getMoreResults(); // returns false

> You may have more success using something like this:
>
>>   PreparedStatement pstmt = con.prepareStatement("UPDATE something with no RETURNING clause", new String[] {
"some_column"}); 
>>   int updateCount = pstmt.executeUpdate();
>>   ResultSet results = pstmt.getGeneratedKeys();

That indeed works!

But I still think the behaviour with getMoreResults() is - at least - confusing ;)

Thanks a lot for all your patience!

Thomas


pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: getUdateCount() vs. RETURNING clause
Next
From: Thomas Kellerer
Date:
Subject: getTablePrivileges() does not report TRUNCATE privilege correctly