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

Re: Retrieve auto-generated key.

From: "gcj" <gauss21(at)comcast(dot)net>
To: "'Sangeeta'" <Sangeeta(dot)shah(at)bluenog(dot)com>,<pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Retrieve auto-generated key.
Date: 2008-11-04 21:49:46
Message-ID: 8F37B3B9EB674AB68387159501E92F75@Serotonin (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Have you tried using the "RETURNING" keyword?  For example.


String sql = " INSERT INTO \"YourSchemaName\".\"YourTableName\"
(\"YourColName1\", \"YourColName2\") VALUES (?, ?) RETURNING

PreparedStatement ps = con.prepareStatement(sql);

ps.setString(1, "someValue");

ps.setString(2, "anotherValue");

rs = ps.executeQuery();

if ( {

  System.out.println("Auto-generated key is:" +rs.getInt(1));



Hope this helps


From: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Sangeeta
Sent: Tuesday, November 04, 2008 8:46 AM
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [JDBC] Retrieve auto-generated key.




Ability to retrieve auto-generated key is one of the key features of JDBC3. 
I tried using prepareStatement(String sql, int autoGeneratedKeys) ,
prepareStatement(String sql, int[] columnIndexes) and
prepareStatement(String sql, String[] columnNames) but with no success . It
returned with exception message as "Returning autogenerated keys is not


I know there is already one thread for retrieve auto-generated key but look
like that thread does not have one distinct   solution.

Is there any patch or workaround to retrieve auto-generated key ?





In response to

pgsql-jdbc by date

Next:From: Alexander PanzhinDate: 2008-11-04 22:42:23
Subject: Re: Retrieve auto-generated key.
Previous:From: Alexander PanzhinDate: 2008-11-04 16:38:21
Subject: Re: Passing Array from Java to Postgres

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