Re: getXXX throws SQLException while on insert row

From: Kris Jurka <books(at)ejurka(dot)com>
To: Prasanth Reddy <dbadmin(at)nqadmin(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: getXXX throws SQLException while on insert row
Date: 2007-12-01 09:42:40
Message-ID: Pine.BSO.4.64.0712010435440.12362@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Mon, 29 Oct 2007, Prasanth Reddy wrote:

> Should the below code throw an SQLException?
>
> rs.moveToInsertRow();
> rs.updateInt("account_id", 1023);
> rs.getInt("account_id"); - shouldn't this return 1023 rather than
> throwing SQLException?
>
> Below is the exception:
> org.postgresql.util.PSQLException: ResultSet not positioned properly,
> perhaps you need to call next.

It's not clear. Reading the JDBC spec it doesn't seem to say anything
about fetching data from a partially updated ResultSet. Also note that
this doesn't work as you might expect for an update of a regular ResultSet
row.

int i = rs.getInt(1);
rs.updateInt(1, i+1);
// here j will be == i, not i+1.
int j = rs.getInt(1);

We store the pending values in a separate area because it makes things
like cancelRowUpdates or just navigating away from the updated row without
issuing updateRow easy. While I can see the utility of being able to
fetch the updated values, it would complicate the driver, so I'm not
excited about it unless you can point to some documentation that says we
should.

Kris Jurka

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2007-12-01 12:35:38 Re: prepared statement using postgres array
Previous Message Kris Jurka 2007-12-01 09:19:17 Re: "create type" custom types not supported by JDBC