| From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
|---|---|
| To: | pgsql-jdbc(at)postgresql(dot)org |
| Subject: | Re: getUdateCount() vs. RETURNING clause |
| Date: | 2009-11-25 14:03:43 |
| Message-ID: | hejdfj$3rs$1@ger.gmane.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Thomas Kellerer | 2009-11-27 22:40:50 | getTablePrivileges() does not report TRUNCATE privilege correctly |
| Previous Message | Oliver Jowett | 2009-11-25 13:42:27 | Re: getUdateCount() vs. RETURNING clause |