• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to synchornize "select"?

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
i'm running a query,
select max(idfield) from mytable query to get the maximum ID generated so far and then generating a new ID as the max(idfield)+1.
i use oracle database (i donno if there is a autoincrement in there). now, my problme is, i have the above query in a servlet so if two client request comes simultaenously and both of them get the same max(idfield) as a select query then i'd end up generating same ID for both of the request, right?
how can i synchroniz this access? will,
synchronize {
- run select query
- generate new id
}
will work?
regards
maulin
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle has sequences which you should use for creating the IDs.
Here's how you create a sequence in the database (see Oracle documentation for more options):

Once you've got a sequence set up, here's how you fetch an "auto-incremented" value from the sequence:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic