jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes getGeneratedKeys() + batchUpdate 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 "getGeneratedKeys() + batchUpdate" Watch "getGeneratedKeys() + batchUpdate" New topic

getGeneratedKeys() + batchUpdate

C.P Sanchalanam

Joined: Aug 05, 2006
Posts: 15
Hello there,

Is it allowed to use getGeneratedKeys() on PreparedStatement to get all the generated unique IDs (seq.nextval) generated in a batch update? please advice.

If it is not allowed please could you suggest a method to retrieve sequence Ids from a batch update.

Here is the requirement:

I have 2 tables DataTable1 (columns: ID, Name) and DataTable2 (REF-ID, value) and the relationship between these table is one-to-many:

I am using an batch insert into DataTable1 to add multiple rows and each row's ID is unique and it is generated by seq.nextval. Now, after this batch insert I need to retrieve all the generated IDs and use these IDs to inser data into the second table(DataTable2).

Thanks for your help.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Sanchi Sanchi",
Please check your private messages regarding an important administrative matter.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
C.P Sanchalanam

Joined: Aug 05, 2006
Posts: 15
Hello All, I would appreciate any views or suggesting on this. Hoping to hear from someone.

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

You would need to try it. My guess is that it would be vendor specific and would either return the generated keys, or would throw an Exception when called from the PreparedStatement
I agree. Here's the link: http://aspose.com/file-tools
subject: getGeneratedKeys() + batchUpdate
jQuery in Action, 3rd edition