JdbcTemplate jdbcTemplate = new JdbcTemplate();
//获取DataSource
DataSource dataSource = jdbcTemplate.getDataSource();
//获取Connection
Connection connection = DataSourceUtils.getConnection(dataSource);
//关闭jdbc自动提交
connection.setAutoCommit(false);
try{
//处理逻辑(新增、修改)标签:事务,jdbc,setAutoCommit,开启,connection,JdbcTemplate,jdbcTemplate,dataSource From: https://www.cnblogs.com/sdou/p/17388788.html
}catch(Exception e){
//如果报错,则回滚
connection.rollback();
}finally{
//处理结束后开启jdbc自动提交,关闭jdbc连接
connection.setAutoCommit(true);
if(connection != null){
connection.close();
}
}