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

猜你喜欢

转载自blog.csdn.net/xiaoqiu_cr/article/details/79342587