java事务处理问题
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup(
"java:/comp/env ");
DataSource ds = (DataSource) envContext.lookup( "jdbc/sample_db ");
Connection conn = ds.getConnection();
conn.setAutoCommit(false);;
String sql = "delete from cateringmsg where id= " + id;
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
stmt.executeUpdate( "delete from agiomsg where sid= 'R "+id+ " ' ");
stmt.executeUpdate( "delete from slwordmsg where sid= 'R "+id+ " ' ");
stmt.executeUpdate( "delete from imgesmsg where sid= 'R "+id+ " ' ");
stmt.executeUpdate( "delete from pricemsg where sid= 'R "+id+ " ' ");
conn.commit();
conn.setAutoCommit(true);
stmt.close();
conn.close();
return true;
} catch (Exception e) {
conn.rollback();
System.out.println( "异常: " + e.toString());
return false;
}
catch中回滚不了事务 怎么解决?
------解决方案--------------------呵呵,
try {
……
Connection conn = ds.getConnection();
conn.setAutoCommit(false);;
String sql = "delete from cate