码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis中在关闭连接之前为什么要设置自动提交为true?

时间:2019-11-09 19:58:03      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:some   ack   mit   work   data   sel   date   pre   exception   

public void close() throws SQLException {
    if (connection != null) {
      resetAutoCommit();
      if (log.isDebugEnabled()) {
        log.debug("Closing JDBC Connection [" + connection + "]");
      }
      connection.close();
    }
  }

mybatis中的JdbcTransaction中的close方法, resetAutoCommit()方法是设置autoCommit=true。

源码:

 protected void resetAutoCommit() {
        try {
          if (!connection.getAutoCommit()) {
            // MyBatis does not call commit/rollback on a connection if just selects were performed.
            // Some databases start transactions with select statements
            // and they mandate a commit/rollback before closing the connection.
            // A workaround is setting the autocommit to true before closing the connection.
            // Sybase throws an exception here.
            if (log.isDebugEnabled()) {
              log.debug("Resetting autocommit to true on JDBC Connection [" + connection + "]");
            }
            connection.setAutoCommit(true);
          }
        } catch (SQLException e) {
          log.debug("Error resetting autocommit to true "
              + "before closing the connection.  Cause: " + e);
        }
      }

 

Mybatis中在关闭连接之前为什么要设置自动提交为true?

标签:some   ack   mit   work   data   sel   date   pre   exception   

原文地址:https://www.cnblogs.com/kyuan1121/p/11827037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!