标签: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