try{??
????????? ……??????
????????? con.setAutoCommit(false);??
????????? ……???? //執(zhí)行你的任務(wù)??
????????? ……??
????????? con.commit();??
????????? con.setAutoCommit(true);??
???
? }catch(SQLException?? ex)?? {??
????????? System.err.println("SQLException:?? "?? +?? ex.getMessage());??
????????????????? if?? (con?? !=?? null)?? {??
????? try?? {??
????????? System.err.print("Transaction?? is?? being?? ");??
????????? System.err.println("rolled?? back");??
????????? con.rollback();??
??????? }?? catch(SQLException?? excep)?? {??
? System.err.print("SQLException:?? ");??
? System.err.println(excep.getMessage());??
? }??
? }??
? }
finaly{
try{
if(con?? !=?? null){
con.close();
}
setAutoCommit(false)之后,你必須手工調(diào)用commit ? 或者 ? rollback來確認(rèn)事務(wù)是提交還是回滾 ?
? 最好再調(diào)用setAutoCommit(true)來關(guān)閉事務(wù)狀態(tài)再close連接
大盤預(yù)測
國富論
posted on 2009-02-13 11:42
華夢行 閱讀(415)
評論(0) 編輯 收藏 所屬分類:
JDK