|
发表于 2014-11-20 11:50:18
|
显示全部楼层
参考 public static void Transaction() {
java.sql.Connection conn = null;
java.sql.PreparedStatement pstmt = null;
com.justep.system.data.Transaction tx = null;
CallableStatement proc = null;
try {
// 取得数据库连接
tx = new com.justep.system.data.Transaction();
conn = tx.getConnection("/appdemo/test/data");
tx.begin();
// 调用存储过程insert into
proc = conn.prepareCall("{ call RQ_insert(?,?,?) }");
executeProcedure(proc,UUID.randomUUID().toString().toUpperCase().replaceAll("-", ""),"123","321");
// 调用存储过程insert into
int abc = 2 / 0;
executeProcedure(proc,UUID.randomUUID().toString().toUpperCase().replaceAll("-", ""),"456","654");
tx.commit();
} catch (Exception ex) {
try {
tx.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
throw new RuntimeException(ex);
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("##close.SQLException");
}
}
}
|
|