permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes Using generatedKeys() with PostGRESQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Using generatedKeys() with PostGRESQL " Watch "Using generatedKeys() with PostGRESQL " New topic

Using generatedKeys() with PostGRESQL

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Folks,
I was trying to use the generatedKeys() method of PreparedStatement to get the autoincrementing primary key of my resultset in an insert query .However it threw a PSQL exception stating --
org.postgresql.util.PSQLException: This method is not yet implemented.

Is there a workaround or another method to implement it through the same query as we do in the case of generatedkeys()? I'm aware of using currval and nextval,any other methods that somebody could suggest?

Learning and Learning!-- Java all the way!
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

I believe, generatedKeys() method will be implemented by the JDBC drive you use to connect to a Database.
In case of Oracle this is implemented, however, for PostGreSQL I am not sure whether this is implemented.
Please check if this is the case and try getting a driver for PostGreSQL that supports this feature, otherwise you may need to write custom code to generate the next key.

Not many get the right opportunity !
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Madhan!
Thanks for the reply .
Can you /anyone suggest any postgresql drivers that support the same?
I agree. Here's the link:
subject: Using generatedKeys() with PostGRESQL
It's not a secret anymore!