wood burning stoves 2.0*
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with bulk update and auto_increment" Watch "problem with bulk update and auto_increment" New topic
Author

problem with bulk update and auto_increment

Ravinder Rana
Greenhorn

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.

Thanks
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

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

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
 
 
subject: problem with bulk update and auto_increment
 
Similar Threads
Need Help regarding Apache James
What effects by using a lot of foreign keys?
Need Open Source email sending application
Glassfish + jdbcrealm
OJB - Two entries in Table after commit