当前位置:网站首页>We found a huge hole in MySQL: do not judge the number of rows affected by update!!!
We found a huge hole in MySQL: do not judge the number of rows affected by update!!!
2022-07-01 06:59:00 【Java technology stack】
Click on the official account ,Java dried food Timely delivery 
source :cnblogs.com/yjmyzz/p/13562182.html
In the business system , Use update Statement updating data is a normal scenario , We often pass through update Number of rows updated , To make some business judgments , Similar to the following pseudo code :(mybatis + mysql scene )
if (xxxMapper.updateByPrimaryKeySelective(entity)>0){
// The update is successful , Do other business processing
}But there's a hole ,mysql in update Number of rows affected >0 It's conditional , If there is a table :

There's only one record in it (ID=1), We use it update Update one ID=1 This record of . in addition , newest MySQL The interview questions are sorted out , You can Java Interview library applet online brush questions .

This line was successfully updated , The number of affected lines is 1, Taken for granted , Then put this update Statement again :

Now , The number of affected rows returned is 0, in other words , When the record to be updated is the same as the old value of the original record ,mysql In fact, there will be no update ..
In other words , If the data transmitted from the upstream , Equal to the old value of the database itself , When there is no change ,update The number of lines affected by the statement is 0. This is different from another scenario :" Update a record that doesn't exist , Affect the number of rows and return 0" Indistinguishable .

Conclusion : Do not use update The number of lines affected by the statement makes important business judgments !


Spring Boot After the scheduled task is started , How to stop automatically ?
Java 8 Sort of 10 A pose , What a show !
23 Design mode and Practice ( Very comprehensive )
Spring Boot Protect sensitive configurations 4 Methods !
Face a 5 year Java, Neither thread can exchange data !
Why does Ali recommend LongAdder?
A new technical director : No code writing with headphones ..
Don't use it. System... It's time ,StopWatch Good use of explosion !
Java 18 Official release ,finalize deprecated ..
Spring Boot Admin Born in the sky !
Spring Boot Learning notes , This is so complete !
Focus on Java Technology stack, see more dry goods


obtain Spring Boot Practical notes !
边栏推荐
- Is fixed investment fund a high-risk product?
- 问题:OfficeException: failed to start and connect(三)
- 2022 Jiangsu Vocational College skills competition (secondary vocational school) network construction and application open competition volume
- Using fuseki query when there are multiple models in TDB
- Buildreoot override mechanism
- DC-4靶机
- Why are so many people turning to product managers? What is the development prospect of product manager?
- 关于图灵测试和中文屋Chinese room的理解
- [wechat applet] view container and basic content components
- [wechat applet low code development] second, resolve the code composition of the applet in practice
猜你喜欢

树莓派4的WiFi设置

ctfshow-web351(SSRF)

WiFi settings for raspberry Pie 4

开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开

【LINGO】求解二次规划

如何进入互联网行业,成为产品经理?没有项目经验如何转行当上产品经理?

问题:OfficeException: failed to start and connect(三)

【Tikhonov】基于Tikhonov正则化的图像超分辨率重建

Jena default inference query based on OWL

发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
随机推荐
AI视频智能平台EasyCVR设备录像出现无法播放现象的问题修复
MySQL learning
Problem solving: officeexception: failed to start and connect (I)
Is the account opening of Huafu securities safe and reliable? How to open Huafu securities account
DC-4 target
ctfshow-web351(SSRF)
JSP - paging
rclone配置minio及基本操作
Solve the problem that the class defined in meta-inf.services cannot be read
树莓派4的WiFi设置
【Tikhonov】基于Tikhonov正则化的图像超分辨率重建
[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering
[wechat applet] view container and basic content components
Resttemplate use
[Tikhonov] image super-resolution reconstruction based on Tikhonov regularization
SQL learning notes nine connections 2
The game is real! China software cup releases a new industrial innovation competition, and schools and enterprises can participate in it jointly
发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
[wechat applet] to solve button, input and image components
為什麼這麼多人轉行產品經理?產品經理發展前景如何?