Home > Back-end >  Java code is order to the operation of the database, or a simultaneous?
Java code is order to the operation of the database, or a simultaneous?

Time:01-02

Is order code to the operation of the database, or a simultaneous?
Such as a piece of code on the same table in the database in the two sequential operation:
Before operating A: modify the certain values in the table
B: operation again according to the value of A modified query operation
Code execution process is waiting for the operation carried out on the table again after the modification operation B, or A code to run the operation, but the database to finish table has not changed, the code has been carried out operation B?
Who is a great god know running mechanism, can you answer?

CodePudding user response:

To understand the transaction thank you

CodePudding user response:

This depends on the use of technology combination, if only the JDBC, depending on the transaction

CodePudding user response:

Database is dead, and its synchronization is not on your own, but by how external operations, such as the consistency problem you said, before using SQL is like this:
Rewrite the data, the need to select the from x tablex where id=xx for update, pay attention to the end there's a for update, so the rows of data will be locked, can't into other updates, thus avoiding the concurrent cover each other, only the first after a commit, the latter to operate the data,

But it's not all, such as the first user opens, the data content is a, he is ready to amend the him to b, when he opened the second user has opened the data, he found that the data must be modified to c, and so he did the modification, then after they are submitted, if you don't do any special treatment, they all don't know the data from a to b to c, or into a c to b, so the following is a complete approach:

1, add a field on the data structure: updatetime (yyyymmddhh24miss)

2, open the user data, the contents of the currently displayed behind the field, that is to open a, as well as its update time together be query and stored in the client

3, the user submits a ~ b changes, along with all the time to step on the open back together

Select x 4, the background and updatetime from tablex where id=xx for update, check whether the select out time after agree with step back in time, if not consistent, that have other client to modify the data before, if you agree to modify, modify the synchronous updatetime the latest sysdate
  • Related