jdbc事务并发现象

1、脏读


1.1避免脏读现象

#避免脏读

#开启事务A
start transaction;
#关闭自动提交
set @@autocommit = 0
show variables like '%autocommit%'
update student set name = 'kangkang232' where id =1;
select * from student where id =1
rollback;
commit;
#开启事务B
start transaction;
#设置隔离级别为读已提交
set session transaction isolation level read committed;
select * from student where id =1
commit;

2、不可重复读


#避免重复读
#事务A
commit;
start transaction;
update student set name = 'cc' where id = 1;
commit;
#事务B
commit;
set session transaction isolation level  repeatable read;
start transaction;
select * from student where id = 1;

3、幻读

#避免幻读
#事务A
commit;
set session transaction isolation level serializable;
start transaction; 
select * from student where id =1;
select * from student where id =1;

#事务B
commit;
start transaction;
insert into student values(12345,'mdm',110);
commit
欢迎关注我的公众号:小秋的博客 CSDN博客:https://blog.csdn.net/xiaoqiu_cr github:https://github.com/crr121 联系邮箱:rongchen633@gmail.com 有什么问题可以给我留言噢~
原文地址:https://www.cnblogs.com/flyingcr/p/10326906.html