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

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfacespgsql-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.


	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 T Mount peter(at)retep(dot)org(dot)uk
      Main Homepage:
PostgreSQL JDBC Faq:
 Java PDF Generator:

In response to

pgsql-interfaces by date

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

pgsql-sql by date

Next:From: St├ęphane FILLONDate: 1999-09-14 18:14:15
Subject: BUG with UNIQUE clause
Previous:From: Esteban Chiner SanzDate: 1999-09-14 17:14:22
Subject: Primary key on NUMERIC type

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