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
This article shares the specific code of JavaScri...
The role of init_connect init_connect is usually ...
1. List query interface effect Before introducing...
I have newly installed MySQL 5.7. When I log in, ...
This article mainly introduces the wonderful use ...
There are two ways to delete data in MySQL: Trunc...
Now that we have finished the transform course, l...
Table of contents MySQL Common Functions 1. Numer...
1. Introduction Nginx is a free, open source, hig...
Preface Not long ago, I saw an interesting proble...
Basic Use <!DOCTYPE html> <html lang=&qu...
background Last week the company trained on MySQL...
This article example shares the specific code of ...
This article shares the specific code of the vue3...
Table of contents Achieve results Introduction to...