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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

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: Wed, 25 Nov 2009 15:03:43 +0100
  • Message-id: <hejdfj$3rs$1@ger.gmane.org> <text/plain>

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





Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group