This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

primary generator using MySQL

 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic