Re: [INTERFACES] JDBC and getting just assigned serial number

From: Peter Mount <peter(at)retep(dot)org(dot)uk>
To: Christoph Steinbeck <steinbeck(at)ice(dot)mpg(dot)de>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] JDBC and getting just assigned serial number
Date: 1999-09-14 17:33:16
Message-ID: Pine.LNX.4.10.9909141825540.543-100000@maidast.retep.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

On Mon, 13 Sep 1999, Christoph Steinbeck wrote:

> Hi,
>
> I'm thrilled to see that there is some kind of discussion running in the
> C area on the exact equivalent of my very recent JDBC problem.
> I insert a row into a table where one field is a SERIAL. This SERIAL, of
> course, is automatically assigned by PostgreSQL. How do I get this
> number immeadiately after inserting the row? When I issue the command
> with psql I get back some kind of number which presumably is the OID.
> Getting just this one would be fine too because I need it for
> referencing.

There's not a standard way, but we do have an extension method that does
the job: getResultStatusString()

This method was added as someone else asked for it in the distant past.

ie:

Statement st = conn.createStatement();

.. your code that either runs st.executeQuery() or
st.executeUpdate() ..

then for JDK1.1.x:
String returncode = ((postgresql.jdbc1.Statement)st).getResultStatusString();

or for Java2:
String returncode = ((postgresql.jdbc2.Statement)st).getResultStatusString();

PS: Sorry, you have to state the driver version (jdbc1 or jdbc2), although
this will be fixed in 6.6, and will become postgresql.Statement.

Peter

--
Peter T Mount peter(at)retep(dot)org(dot)uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Michael Meskes 1999-09-14 18:22:15 Re: [INTERFACES] Transaction: Begin, Lock
Previous Message Sean W. Ellis 1999-09-14 16:02:20 Check boxes with Access

Browse pgsql-sql by date

  From Date Subject
Next Message Stéphane FILLON 1999-09-14 18:14:15 BUG with UNIQUE clause
Previous Message Esteban Chiner Sanz 1999-09-14 17:14:22 Primary key on NUMERIC type