jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes problem with bulk update and auto_increment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem with bulk update and auto_increment" Watch "problem with bulk update and auto_increment" New topic

problem with bulk update and auto_increment

Ravinder Rana

Joined: Dec 07, 2006
Posts: 19
Hi All,

I need some help from you guys regarding bulk update. The scenario is as follows:

I have 3 tables in my DB: Person, Person_Phone_Numbers and Person_custom_info

Person table has a id(AUTO_INCREMENT)and Person_Phone_Numbers and Person_custom_info tables has this as their foreign key.

The no. of records which I have to insert at a time will be somewhere between 50 to 200, so I want to do a batch insert i.e. first insert all Person info followed by Person_Phone_Numbers and Person_custom_info.

Now the problem is, to insert data in Person_Phone_Numbers and Person_custom_info tables I need the Person ID value's. Is there a way to get these values? I am using MySQL as database.

All inputs appreciated.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2562

You can use java.sql.Statement.getGeneratedKeys().
It's documented in the MySQL 5.0 Reference Manual, Basic JDBC Concepts: Retrieving AUTO_INCREMENT Column Values.

Regards, Jan

OCUP UML fundamental and ITIL foundation
I agree. Here's the link: http://aspose.com/file-tools
subject: problem with bulk update and auto_increment
It's not a secret anymore!