How to set autocommit to false in spring jdbc template

前端 未结 7 1742
天命终不由人
天命终不由人 2020-12-08 21:01

Currently I\'m setting autocommit to false in spring through adding a property to a datasource bean id like below :

   

        
相关标签:
7条回答
  • 2020-12-08 21:32

    You need to get the current connection. e.g.

    Connection conn = DataSourceUtils.getConnection(jdbcTemplate.getDataSource());
        try {
            conn.setAutoCommit(false);
    
            /**
             * Your Code
             */
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            e.printStackTrace();
        }
    
    0 讨论(0)
提交回复
热议问题