Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Prevent same row from being updated by another user

o_O
Loyal Member
Joined
Nov 24, 2004
Messages
147
Reaction score
2
Hi there,

I have a question about concurrency in Java - JDBC.

Currently i have this SQL query, i don't use Hibernate in my codes so im looking for other alternative. I read about optimistic locking but not sure how to implement it

When two user click Update button at the same time.

select * from myTable where id = 1
update myTable set test = '1' where id = 1

When user A execute the following

select * from myTable where id = 1
update myTable set test = '1' where id = 1

The test column updated to 1

When user B execute the following

select * from myTable where id = 1
update myTable set test = '2' where id = 1

The test column updated to 2

In this case, I'm trying to prevent user B from updating test column to 2 as the row has already been updated to 1 by user A

Is there a way I can prevent user B from updating?
 

cMu

Elite Diviner
Joined
Jan 8, 2017
Messages
427
Reaction score
133
use the USER ID in your UPDATE statement
 
Joined
Jun 10, 2009
Messages
658
Reaction score
140
You can use the ROWLOCK feature which is available in most SQL databases to lock the row while one update is under progress so that only one process updates the row at a time!
 
Back
Top