File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes primary generator using MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "primary generator using MySQL" Watch "primary generator using MySQL" New topic
Author

primary generator using MySQL

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hi, guys:

I need a primary key (sequence) generator for multiple tables.

I will have to programatically store/retrieve primary keys and save them as
foreign keys for other tables using Java JDBC.

I also looked at AUTO_INCREMENT of MySQL, but how can I use it for multiple tables and retrieve the most recent key to use without producing duplications?

regards,
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
I've not done it, but I'd think you could use auto increment and then Statement.getGeneratedKeys() (which of course PreparedStatement inherits...)
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by stu derby:
I've not done it, but I'd think you could use auto increment and then Statement.getGeneratedKeys() (which of course PreparedStatement inherits...)


I don't know that the MySQL JDBC driver supports that method. Last time I tried it did not.


%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primary generator using MySQL