Prevent user from editing the same record

2019-03-04 07:41发布

问题:

I'm developing a Multiple user application on same network usign MySQL & Java. What I'm looking for is: User A: Modifying Record 100 User B: Try to view or modify same record 100.

I want the application to return error message for User B, that record already editing by another user.

How can i do this?

回答1:

Include an edit_timestamp in the tables of your database you want to prevent from multiple users updating, which you'll update every time anyone edit the row.

In your forms, include a hidden field edit_timestamp with the value stored in the row you're editing.

When you receive a edit form, check if the edit_timestamp of the row that you're editing hasn't changed. If it has changed, someone has edited the row and throw an error to the user. If it hasn't changed, update the row and the edit_timestamp field