Use a transaction and an InnoDB table.
http://dev.mysql.com/doc/refman/5.0/en/transactional-commands.html
Or, use the LOCK TABLES command:
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
An ideal solution (in my mind) is to use a stored procedure to read the
table, increment the current value, update the table, and return the new
UID to the caller - all inside a transaction. Used to do this with
Sybase all the time; never tried it with MySQL's transactions and stored
procedures, but don't know why it wouldn't work.
Dan
balaraju mandala wrote:
Hi Comunity,
I am facing concurrency problem. The scenario is, I have a table, the
primary key of that table say 'uid' is a unique number, which is used by my
application. So every time i fire a query, i get max(uid) i read this
ResultSet from my Java application. I increament this uid to +1. This
resulted 'uid' will be updated to the Table. This table is used by more
than
one thread at any given time. So if some threads fire SQL command at same
time, they are getting same uid and result is a duplicate values Exception.
I cannot use AUTOINCREMENT. Please anybody have any solution for this?
--
Dan Buettner
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]