在dao中开始事物
try
调用存储过程A
调用存储过程B
设置状态信息
没有错误就commit
catch
rollback为何设置状态出错或执行B出错误,执行rollback了而过程A执行的操作没有回滚呢?? 各位大虾帮帮忙!
try
调用存储过程A
调用存储过程B
设置状态信息
没有错误就commit
catch
rollback为何设置状态出错或执行B出错误,执行rollback了而过程A执行的操作没有回滚呢?? 各位大虾帮帮忙!
int n=0;
int f=5;
try {
conn.setAutoCommit(false);
String sql2="delete from student where classid=?";
pstm=conn.prepareStatement(sql2);
pstm.setInt(1, 1);
pstm.executeUpdate();
String sql1="delete from class where classid=?";
pstm=conn.prepareStatement(sql1);
pstm.setInt(1, 1);
n=pstm.executeUpdate();
conn.commit();
} catch (SQLException e) {
// TODO Auto-generated catch block
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("请删除班级下相关学生");
}
return n;
}
getUserTransaction();
if (utx.getStatus() ==
javax.transaction.Status.STATUS_NO_TRANSACTION) {
utx.begin();
} else {
utx = null;
}if (utx != null) {
utx.commit();
}
}catch (Exception e) {
if (utx != null) {
try {
utx.rollback();
} catch (Exception epx) {
System.out.println("事务回滚错误:" + epx.toString());
}
}
sysCommethod.Exception("添加数据错误:", form.getDsName(), e, servlet);
}