spring+DbUtils开发事务怎么控制呢? 如题:
项目中用spring3-mvc+DbUtils spring+DbUtils开发事务怎么控制呢?
public int updateTransaction(String [] sqlArr,Object [] sqlParamsArr){
int affectedRows = 0;
if (sqlArr.length != sqlParamsArr.length) {
logger.error("updateTransaction error:sql tasks not equal param tasks!");
return affectedRows;
}
if (sqlArr.length == 0){
return affectedRows;
}
Connection con = null;
try {
con = dataSource.getConnection();
con.setAutoCommit(false);
queryRunner = new QueryRunner(dataSource);
for (int i = 0 ; i < sqlArr.length ; i++) {
String sql = sqlArr[i];
Object[] params = (Object[])sqlParamsArr[i];
if (params == null) {
affectedRows += queryRunner.update(sql);
} else {
affectedRows += queryRunner.update(sql, params);
}
}
} catch (SQLException e) {
logger.error("updateTransaction error:Error occured while attempting to updateTransaction data!", e);
affectedRows = 0;
try {
logger.error("updateTransaction info:transaction roll back!");
con.rollback();
} catch (SQLException e1) {
logger.error("updateTransaction error:Error occured while updateTransaction do rollback()!");