String ID = id;
db = new getConnection();
Connection con = db.getConnection();
try {
con.setAutoCommit(false);
db.executeUpdate("delete from helloworld where ID=" + ID); //更新操作1
db.executeUpdate("delete from helloworld _book where ID=" + ID); //更新操作2
db.executeUpdate("delete from helloworld_user where ID=" + ID); //更新操作3
con.commit();//提交JDBC事务
con.setAutoCommit(true);
db.close();
return “success”;
}
catch (Exception e) {
con.rollBack();//回滚JDBC事务
e.printStackTrace();
db.close();
return “fail”;
}
}
String ID = id;
db = new getConnection();
db.getConnection();
UserTransaction transaction = sessionContext.getUserTransaction();//获得JTA事务
try {
transaction.begin(); //开始JTA事务
db.executeUpdate("delete from helloworld where ID=" + ID);
db.executeUpdate("delete from helloworld _book where ID=" + ID);
db.executeUpdate("delete from helloworld _user where ID=" + ID);
transaction.commit(); //提交JTA事务
db.close();
return”success”;
}
catch (Exception e) {
try {
transaction.rollback();//事务回滚
}
catch (Exception e) {
e.printStackTrace();
}
exc.printStackTrace();
db.close();
return “fail”;
}
}