Prevent same row from being updated by another user

Results 1 to 3 of 3
  1. #1
    o_O TakaShi^^ is offline
    True MemberRank
    Nov 2004 Join Date
    HeavenLocation
    1,266Posts

    Prevent same row from being updated by another user

    Prevent same row from being updated by another user
    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?


  2. #2
    cMuServices cMu is online now
    True MemberRank
    Jan 2017 Join Date
    385Posts

    Re: Prevent same row from being updated by another user

    use the USER ID in your UPDATE statement

  3. #3
    AIGUPH -Jumong- is offline
    True MemberRank
    Dec 2005 Join Date
    /f248/Location
    847Posts

    Re: Prevent same row from being updated by another user

    You can also put if its default 0 where test=0 this way it will only update values with test=0



Advertisement