下面代码不知道你是不是能用得上。 try{
conn=ConnDB.getConnection();
conn.setAutoCommit(false);
st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "INSERT INTO TEAM(TEAM_ID,TEAM_NAME) VALUES ('" + teamid + "','" + teamname + "');";
st.execute(sql); }
catch(SQLException e){
conn.rollback();
e.printStackTrace();
request.setAttribute("errCode",Integer.toString(e.getErrorCode()));
throw new SQLException(e.getMessage());
}
finally{
conn.commit();
st.close();
conn.close();
}
conn=ConnDB.getConnection();
conn.setAutoCommit(false);
st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "INSERT INTO TEAM(TEAM_ID,TEAM_NAME) VALUES ('" + teamid + "','" + teamname + "');";
st.execute(sql); }
catch(SQLException e){
conn.rollback();
e.printStackTrace();
request.setAttribute("errCode",Integer.toString(e.getErrorCode()));
throw new SQLException(e.getMessage());
}
finally{
conn.commit();
st.close();
conn.close();
}
1 出现异常,在catch到后就回滚
2 中间某个条件在业务逻辑上不满足逻辑条件,也该回滚