连续调用多个存储过程,是否可以事务处理

angelataoy 2004-12-13 06:46:04
问个很菜的问题,一般的sql语句可如下进行事务处理,是否可类似调用多个存储过程?在存储过程中不commit即可?谢谢大侠
PreparedStatement prepStmt = null;
int result = 0;
try{

// Get a context for the JNDI look up
Context ctx = new InitialContext();
// Look up myDataSource
datasource = (DataSource) ctx.lookup(Constants.DS_JNDI_NAME);

conn = datasource.getConnection();
conn.setAutoCommit(false);

StringBuffer sql = new StringBuffer("......");


logger.info(sql.toString());


prepStmt= conn.prepareStatement(sql.toString());
prepStmt.executeUpdate();

logger.warn("first update!");
StringBuffer sql2 = new StringBuffer("......");




prepStmt = conn.prepareStatement(sql2.toString());
prepStmt.executeUpdate();




conn.commit();
conn.setAutoCommit(true);

} catch (Exception e) {
try{
conn.rollback();
conn.setAutoCommit(true);
result = -1;
}catch (Exception ex){
logger.warn(ex.toString());
}
}
finally {
if (prepStmt != null){
try {
prepStmt.close();
prepStmt = null;
}
catch (Exception ea) {}
}
try{
closeConnection(conn);
}catch(Exception ec){}

}
return result;

}
...全文
185 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyg158 2004-12-13
  • 打赏
  • 举报
回复
应该是不行的
yellowwee 2004-12-13
  • 打赏
  • 举报
回复
try it yourself~
whbxm2000 2004-12-13
  • 打赏
  • 举报
回复
好像不行

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧