Win a copy of Functional Reactive Programming this week in the Other Languages 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