Home  >  Q&A  >  body text

Mysql中开启事务 不执行rollback 一样不会更新数据 请问!

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

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

高洛峰高洛峰2742 days ago633

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:16:22

    When an error occurs, there is no need to explicitly call rollback, it will automatically roll back.

    But there is a requirement: no error occurs, but we need to judge that after a certain situation is met, we also need to roll back. At this time, we need to explicitly call rollback.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:16:22

    Here:

    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.

    It means that if there are operations in the transaction, the behavior of direct shutdown is determined by the implementation, it may be commit or it may be rollback. The implementation of MySQL is rollback, so there is no problem if you close it directly.

    reply
    0
  • Cancelreply