Re: getting primary key values for inserted records?

From: Kris Jurka <books(at)ejurka(dot)com>
To: Guido Fiala <guido(dot)fiala(at)dka-gmbh(dot)de>
Cc: pgsql-jdbc <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: getting primary key values for inserted records?
Date: 2004-01-27 18:07:00
Message-ID: Pine.LNX.4.33.0401271219200.27584-100000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Tue, 27 Jan 2004, Guido Fiala wrote:

> Hallo,
>
> I'am currently at the point, that after i insert a new Record in a ResultSet
> using insertRow() and using a serial for the primary key of the target table.
>
> Of course i do not call rs.updateInt(primaryKey), as the sequence does get me
> the new value automatically.
>
> However - even using rs.refreshRow() doesn't get me the values, just a requery
> of the ResultSet.
>
> What is the way to go here?
>

Other than reissuing the query, the only real way around this is to
separately issue a nextval call on the sequence and use that value in
rs.updateInt. There is no way for the JDBC driver to know what the
primary key turned out to be otherwise.

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Bhushan Bhangale 2004-01-27 18:18:23 Re: jdbc connection string
Previous Message Kris Jurka 2004-01-27 17:19:03 Re: jdbc connection string