From: andreasfreyer <freyer@online.de>
To: pgsql-jdbc@postgresql.org
Subject: Re: getXXX throws SQLException while on insert row
Date: Sun, 10 Feb 2008 15:50:32 -0800 (PST)
Message-ID: <15403292.post@talk.nabble.com> (raw)
In-Reply-To: <Pine.BSO.4.64.0712010435440.12362@leary.csoft.net>
References: <4726383A.8060909@nqadmin.com>
<Pine.BSO.4.64.0712010435440.12362@leary.csoft.net>
Hello,
according to the Java Documentation form SUN ResultSet.moveToInsertRow is
defined as:
Moves the cursor to the insert row. The current cursor position is
remembered while the cursor is positioned on the insert row. The insert row
is a special row associated with an updatable result set. It is essentially
a buffer where a new row may be constructed by calling the updater methods
prior to inserting the row into the result set. Only the updater, getter,
and insertRow methods may be called when the cursor is on the insert row.
All of the columns in a result set must be given a value each time this
method is called before calling insertRow. An updater method must be called
before a getter method can be called on a column value.
I would like to draw our attention to the the last sentence:
"An updater method must be called before a getter method can be called on a
column value."
That means after setting a value [rs.updateXXX(abc)] it is possible to get
it back [rs.getXXX()] without doing anything else in between [so without
rs.insertRow() or rs.updateRow()].
best regards,
Andreas Freyer
PS: To my knowledge atleast the JDBC Drivers for the following Databases
work like this: MySQLDB, HSQLDB, Derby
Kris Jurka wrote:
>
>
>
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
>
--
View this message in context: http://www.nabble.com/getXXX-throws-SQLException-while-on-insert-row-tp13476706p15403292.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
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: freyer@online.de
Subject: Re: getXXX throws SQLException while on insert row
In-Reply-To: <15403292.post@talk.nabble.com>
References: <4726383A.8060909@nqadmin.com> <Pine.BSO.4.64.0712010435440.12362@leary.csoft.net> <15403292.post@talk.nabble.com>
* 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