Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-jdbc by date

Next:From: Bhushan BhangaleDate: 2004-01-27 18:18:23
Subject: Re: jdbc connection string
Previous:From: Kris JurkaDate: 2004-01-27 17:19:03
Subject: Re: jdbc connection string

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group