From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | getUdateCount() vs. RETURNING clause |
Date: | 2009-11-24 11:45:26 |
Message-ID: | hegh0m$j0f$1@ger.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hi,
I'm having a problem using an UPDATE statement with a RETURNING clause.
It seems I cannot retrieve the number of rows affected using getUpdateCount()
This is my statement
UPDATE my_table
SET the_column = the_column + 1
WHERE id = =
RETURNING the_column;
My Java code is:
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);
I do see the returned ID from the ResultSet but getUpdateCount() always returns -1 even though I know that a row was updated.
What am I missing here?
My Postgres version is: 8.4.1
My driver version is: PostgreSQL 8.4 JDBC4 (build 701)
I'm using Java6 (1.6.0_16)
Regards
Thomas
From | Date | Subject | |
---|---|---|---|
Next Message | Oliver Jowett | 2009-11-25 00:40:30 | Re: getUdateCount() vs. RETURNING clause |
Previous Message | Kris Jurka | 2009-11-20 23:45:57 | Re: COPY and turning off autocommit |