• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protect AutoIncremented Row

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This kind of goes with my other post, but it is different, so here goes.
Let's say I have a table with an auto-incremented field. And when starting a transaction I get the last autoincremented field, then I add 1 to it to get what it will be for my Record.
Now, if I set the isolation level to serializable, is that going to protect my autoincremented value so that it is not used by another transaction?
Also, is there a better way to handle this? I need the autoincremented field value prior to completing the transaction because I am entering data in 2 tables and need that value for the foreign key.
Thanks.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Gregg,
A few questions to help set context. What database are you working with, and are stored procedures an option?
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MySQL and God I wish I could use Stored Procedures. But MySQL is taking their time implementing them. But I'm sure you already know that.
Thanks for trying to help me. I was beginning to wonder....
BTW - Also using the newest Connector/J
[ March 14, 2003: Message edited by: Gregg Bolinger ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At a high level, I'd suggest a synchronized method to access the db: probably synchronized on a given db lock object, which is maybe a static in a differ class all together. This assumes the no other applications are playing with your table, and that any part of the your code that needs to write to that particular table could synchronize on that variable. Thus, you get atomic behavior.
I know the reply's a bit terse, so I'll ask if I've been clear?
M
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to assume that other applications ARE accessing the same table at any time. This is an application that is installed on several PC's.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic