INSERT and get ID - Mailing list pgsql-jdbc

From Peter.Zoche@materna.de
Subject INSERT and get ID
Date
Msg-id 3617A3C21370D045B75C0A40A7A6530D0B37E199@ntexc2buc.do-office.buc.materna.com
Whole thread Raw
Responses Re: INSERT and get ID
Re: INSERT and get ID
Re: INSERT and get ID
List pgsql-jdbc
Hi!

Say I have done the following:

CREATE SEQUENCE myseq

CREATE TABLE foo (
id INTEGER,
val INTEGER,
PRIMARY KEY( id ) );

Is there an easy way to get the id of the newly inserted data set?
So if I do the following:

String insert = "INSERT INTO foo (id, val)
VALUES( nextval('myseq'), 5 )";
int count = statement.executeUpdate( insert );

I only get the row count of inserted rows. Do I have to query the
database again to get the id? Or is there another way? I have tried
statement.executeUpdate( insert, Statement.RETURN_GENERATED_KEYS);
but I get an PSQLException saying that the feature of auto-generated keys
is not supported. (using postgresql 8.0 JDBC3) I googled but I did only find
PostgreSQL-
specific hints, no one for JDBC.

Thanks, Peter

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: jdbc xa patches
Next
From: Oliver Jowett
Date:
Subject: Re: INSERT and get ID