tbwshc

          數(shù)據(jù)庫(kù)事務(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) 評(píng)論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 叙永县| 于都县| 和林格尔县| 华阴市| 临海市| 鹤峰县| 茌平县| 错那县| 海城市| 平潭县| 平原县| 甘孜| 余江县| 渑池县| 青川县| 揭东县| 肇州县| 孙吴县| 河间市| 富蕴县| 白河县| 钟山县| 舞钢市| 永泰县| 仁布县| 云安县| 金秀| 昭平县| 喀喇沁旗| 西乌| 湘潭县| 石景山区| 外汇| 丰城市| 石阡县| 肃宁县| 大同县| 定陶县| 龙陵县| 怀仁县| 榆树市|