MySQL sets up independent writing separation. If you write the following in the code, problems may occur //Enter first this.insert(obj); // Query again Object res = this.selectById(obj.getId()); res: null; A pitfall online: after doing read-write separation, there is a scenario where you want to reuse the method and only pass in an ID. You can directly find an object in the database for subsequent processing. As a result, you can't find it. Various transaction isolation levels have been checked. Finally, it is found that it is a problem of read-write separation, so change the idea to implement it. Additional knowledge: MySQL INSERT insertion condition judgment: insert if it does not exist We often need to perform batch inserts in SQL, requiring: if the record does not exist, insert it; if it does exist, do not insert it. How about using an INSERT statement? For ordinary INSERT insertion, if we want to ensure that no duplicate records are inserted, we can only create a unique constraint for a certain field; Is there a solution that does not create a unique constraint and can be achieved with just one INSERT INTO statement? Answer: Use INSERT INTO IF EXISTS. The specific syntax is as follows INSERT INTO table(field1, field2, fieldn) SELECT 'field1', 'field2', 'fieldn' FROM DUAL WHERE NOT EXISTS(SELECT field FROM table WHERE field = ?) example: INSERT INTO a (order_id, operator, oper_date, memo) SELECT '3', 'onion3', '2017-11-28', 'Test 3' from DUAL where not exists(select order_id from a where operator='onion3' and memo = '测试3'); The above article on solving the problem of not being able to select data after insert due to MySQL read-write separation is all the content that the editor shares with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Implementing a simple whack-a-mole game in JavaScript
>>: After docker run, the status is always Exited
1. Reverse proxy example 1 1. Achieve the effect ...
This article shares the specific code of js canva...
1. Multi-header table code Copy code The code is a...
Since I usually use the docker build command to g...
In an unordered list ul>li, the symbol of an u...
The definition and inheritance of classes in JS a...
Operation effect: html <!-- This element is no...
JS provides three methods for intercepting string...
This article uses examples to describe the three ...
You can write a function: Mainly use regular expr...
It is very easy to delete a table in MySQL, but y...
First we need to know the self-calling of the fun...
I heard that there is an interview question: How ...
BEM from QQtabBar First of all, what does BEM mea...
Use Docker to build a flexible online PHP environ...