Mysql中开启事务 不执行rollback 一样不会更新数据 请问!
高洛峰
高洛峰 2017-04-17 13:14:22
0
2
626

我不执行commit就行了,我还要执行rollback有啥用?

网上查询了下没有什么确切答案,都说要执行rollback才能回滚,可是当我没有执行commit的时候 没有执行rollback 一样回滚了,网上查了很多文字 确没有说不执行rollback和commit一样回滚有啥区别?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

répondre à tous(2)
巴扎黑

出现错误的时候,不用显式调用 rollback,会自动回滚。

但是有一种需求是:没有出现错误,但是我们需要判断满足某种情况后,也需要回滚,这个时候就需要显式调用 rollback 了。

小葫芦

这里:

http://docs.oracle.com/javase...

It is strongly recommended that an application explicitly commits or rolls back an active transaction prior to calling the close method. If the close method is called and there is an active transaction, the results are implementation-defined.

意思是说如果事务里面有操作,直接关闭的行为是由实现确定的,有可能commit有可能rollback。MySQL 的实现是rollback,所以你直接关闭也没有问题。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!