您的位置:首页 > 编程语言 > Java开发

SpringMvc Dao jdbcTemplate设置不自动提交(手动提交)(适用商品抢购等事务)

2016-06-23 20:43 791 查看
try {
con=jdbcTemplate.getDataSource().getConnection();//设置不自动提交
con.setAutoCommit(false);
//jdbcTemplate.query("select xxx from xxx where xxx FOR UPDATE");
//jdbcTemplate.update("xxx");
con.commit();//手动提交
con.setAutoCommit(true);//还原
} catch (Exception e) {
e.printStackTrace();
list = null;
try {//事务回滚
con.rollback();
con.setAutoCommit(true);
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}//还原
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: