數(shù)據(jù)庫事務(wù)處理案例
public int delete(int sID) {dbc = new DataBaseConnection();
Connection con = dbc.getConnection();
try {
con.setAutoCommit(false);// 更改JDBC事務(wù)的默認(rèn)提交方式
dbc.executeUpdate("delete from bylaw where ID=" + sID);
dbc.executeUpdate("delete from bylaw _content where ID=" + sID);
dbc.executeUpdate("delete from bylaw _affix where bylawid=" + sID);
con.commit();//提交JDBC事務(wù)
con.setAutoCommit(true);// 恢復(fù)JDBC事務(wù)的默認(rèn)提交tb方式
dbc.close();
return 1;
}
catch (Exception exc) {
con.rollBack();//回滾JDBC事務(wù)
exc.printStackTrace();
dbc.close();
return -1;
}
}
posted on 2013-05-27 16:59 chen11-1 閱讀(297) 評論(0) 編輯 收藏 所屬分類: java