in my project using java, ibatic and MySql.
Before any updating data into database, i lock the table with SELECT FOR UPDATE
query
eg: SELECT * FROM MEM_MST WHERE MEM_ID = #memId# FOR UPDATE
It make locking the table properly. but the problem is, for example if two client are update the table in same time. first one is lock the table and update but second one is waiting to update until a lock is released. After then second one also update the data. So, first one updated data is overwrite. Please see the following explanation:
Time | Client 1 | Client 2
-------------------------------------------------
1 | SELECT FOR UPDATE |
2 | UPDATE | SELECT FOR UPDATE (Waiting)
3 | COMMIT | (Waiting)
4 | | UPDATE
5 | (Overwritten) | COMMIT
So, Client 1 updated data is lost
What I want to be is want to simply return the error message to Client 2 instead of waiting until a lock is released.
Please advise me the way to solve above mentioned problem.
P.S:
I already set the lock wait timeout to 0 in startup Variables, but it still take about 2 second to tell "Lock wait timeout exceeded" message.
furthermore,SELECT FOR UPDATE NO WAIT
is not working in MySQL