Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Safe way to obtain IDs

Status
Not open for further replies.

Powernic

Programmer
Dec 7, 2004
6
0
0
BE
Hello,

The persistence layer of our java application needs and ID table to obtain new IDs.

The table has one row and one column. What we do to obtain ID's is quite simple :
1. select id from table
2. newid = id + range
3. update table set id = newid
4. commit

This is running fine with a single server.

We are now considering clustered servers, and we must find a way to lock that table/row to avoid another server running the same action at the same time, which would result in duplicate ID's.

I've been told that 'select for update' is not suitable for this situation with DB2.

Could anyone give me ideas on how to procede?

Thanks a lot

Nicolas
 
Create a stored procedure in the db to handle this. Hope this isn't to late.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top