This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Using generatedKeys() with PostGRESQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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?
jQuery in Action, 2nd edition
subject: Using generatedKeys() with PostGRESQL
Similar Threads
hibernate left join not working
How to get MSAccess SQL Query using Java
What is the maximum limit of data can be send to the sever using GET method???
hql with select , where
How to get a blank ResultSet to do update?