起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1625|回复: 0

[分享] X5中的事务

[复制链接]

31

主题

54

帖子

336

积分

中级会员

Rank: 3Rank: 3

积分
336
QQ
发表于 2014-9-16 12:30:31 | 显示全部楼层 |阅读模式
本帖最后由 bingbing4647 于 2014-9-26 15:33 编辑




----------------------------------------------------------------------------------------------------------------------------------------------------------------
public static void deleteData(String DJH){
                Connection conn=null;
                PreparedStatement  pstmt = null;
                Transaction tx=null;
                try {
                        tx = new com.justep.system.data.Transaction();
                        conn = tx.getConnection("/OA/geologySurvey/data");
                        tx.begin();
                        String delete_DJDCB ="Delete  ZD_DJDCB where DJH='"+DJH+"'";
                        pstmt  = conn.prepareStatement(delete_DJDCB);
                        pstmt.executeUpdate();
                        
                        String delete_JZBSB ="Delete  ZD_JZBSB where DJH='"+DJH+"'";
                        pstmt  = conn.prepareStatement(delete_JZBSB);
                        pstmt.executeUpdate();
                        
                        String delete_QLR ="Delete  ZD_QLR where DJH='"+DJH+"'";
                        pstmt  = conn.prepareStatement(delete_QLR);
                        pstmt.executeUpdate();
                        
                        
                        String delete_QSDC ="Delete  ZD_QSDC where DJH='"+DJH+"'";
                        pstmt  = conn.prepareStatement(delete_QSDC);
                        pstmt.executeUpdate();
                        
                        String delete_ZJB ="Delete  ZD_ZJB where DJH='"+DJH+"'";
                        pstmt  = conn.prepareStatement(delete_ZJB);
                        pstmt.executeUpdate();
                        
                        tx.commit();
                        
                } catch (Exception e) {
                        e.printStackTrace();
                        try {
                                System.out.println("__________rollback");
                                tx.rollback();
                        } catch (SQLException e1) {
                                e1.printStackTrace();
                        }
                }finally{
                        if(pstmt!=null){
                                try {
                                        pstmt.close();
                                } catch (SQLException e) {
                                        e.printStackTrace();
                                }
                        }
                        //平台提供的事务是会自动关闭的,不用关闭
//                        if(conn!=null){
//                                try {
//                                        conn.close();
//                                } catch (SQLException e) {
//                                        e.printStackTrace();
//                                }
//                        }


                }
               
        }

-------------------------------------------------------------------------------
-------------------------------------------------------------------------------



private static String getRecieveSysIdByAddress(String code) throws SQLException {
                String selectSql = "select b.fid from do_allcocation b " +
                "where b.FAREACODE='" + code + "'";
                Connection con = null;
                Statement stmt = null;
                ResultSet set = null;
                String result = "";
                try {
                        con = ModelUtils.getConnection("/OA");
                        stmt = con.createStatement();
                        set = stmt.executeQuery(selectSql);
                        
                        
                        if(set.next()){
                                result = set.getString("FID");
                        }
                } catch (NamingException e) {
                        e.printStackTrace();
                } catch (SQLException e) {
                        e.printStackTrace();
                }finally{
                        if(set!=null){
                                set.close();
                        }
                        if(stmt!=null){
                                stmt.close();
                        }
                        if(con!=null){
                                con.close();
                        }
                }
                return result;
        }

Transaction trans = com.justep.system.context.ContextHelper.getTransaction();
System.out.print("\r\n---scs--"+trans.getStatus());
System.out.print("\r\n---scs--"+trans.hashCode());
trans.rollback();

0:com.justep.system.data.Status.ACTIVE  活动状态,表示事物已启动
3:com.justep.system.data.Status.COMMITTED  事物已提交
10: com.justep.system.data.Status.LAZY 懒惰状态,表示一部分连接的事物已启动
6:com.justep.system.data.Status.NO_TRANSACTION 未启动事物
4:com.justep.system.data.Status.ROLLEDBACK 事物已回滚






评分

参与人数 1 +5 收起 理由
jishuang + 5 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-5-18 06:37 , Processed in 0.060521 second(s), 27 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表