pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: getUdateCount() vs. RETURNING clause
Date: Wed, 25 Nov 2009 15:03:43 +0100
Message-ID: <hejdfj$3rs$1@ger.gmane.org> (raw)
In-Reply-To: <4B0D3443.7050902@opencloud.com>
References: <hegh0m$j0f$1@ger.gmane.org>
	<4B0C7CFE.50106@opencloud.com>
	<heimgq$sdo$1@ger.gmane.org>
	<4B0D1164.1060006@opencloud.com>
	<hej5r1$aqs$1@ger.gmane.org>
	<4B0D2014.3060703@opencloud.com>
	<hej80d$h7p$1@ger.gmane.org>
	<4B0D2DB0.8020707@opencloud.com>
	<4B0D3443.7050902@opencloud.com>

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





view thread (10+ messages)

Message-ID: <hejdfj$3rs$1@ger.gmane.org>
Permalink:  ../hejdfj$3rs$1@ger.gmane.org/
Also on:    postgresql.org/message-id/hejdfj$3rs$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: getUdateCount() vs. RETURNING clause
  In-Reply-To: <hejdfj$3rs$1@ger.gmane.org>
  References: <hegh0m$j0f$1@ger.gmane.org> <4B0C7CFE.50106@opencloud.com> <heimgq$sdo$1@ger.gmane.org> <4B0D1164.1060006@opencloud.com> <hej5r1$aqs$1@ger.gmane.org> <4B0D2014.3060703@opencloud.com> <hej80d$h7p$1@ger.gmane.org> <4B0D2DB0.8020707@opencloud.com> <4B0D3443.7050902@opencloud.com> <hejdfj$3rs$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox