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

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: xtmp

[结贴] 唯一性约束的问题

[复制链接]

3

主题

20

帖子

112

积分

初级会员

Rank: 2

积分
112
 楼主| 发表于 2013-6-27 10:03:44 | 显示全部楼层
public static void caseAcceptProcessBeforeSaveOA_CaseAcceptAction() {
                ActionContext context = ContextHelper.getActionContext();
                Table table = (Table) context.getParameter("table");
                Iterator<Row> rows  = table.iterator();
                while(rows.hasNext()){
                        Row row = rows.next();
                        String fid = row.getString("OA_CaseAccept");
                        java.sql.Connection conn = null;
                        java.sql.PreparedStatement pst = null;
                        java.sql.ResultSet rs = null;
                        String fileCode = row.getString("fFileCode");
                        try{

                                conn = ModelUtils.getConnectionInTransaction("/rbc_OA/legalAffairs/data");
                                String sql = "select count(*) as cc from OA_CaseAccept where fFileCode = ? and FB_TableType='案件受理登记'";
                                pst = conn.prepareStatement(sql);
                                pst.setString(1, fileCode);
                                rs = pst.executeQuery();
                                if(rs.next()){
                                        String a = rs.getString("cc");
                                        if(Integer.parseInt(a)>=1){
                                                throw new RuntimeException("立案编号不允许重复,请修改!");
                                        }
                                }
                        }catch(NamingException e){
                                throw new RuntimeException(e);
                        }catch(SQLException e1){
                                throw new RuntimeException(e1);
                        }finally{
                                try{
                                        if(rs != null){
                                                rs.close();
                                        }
                                        if(pst != null){
                                                pst.close();
                                        }
                                        if(conn != null){
                                                conn.close();
                                        }
                                }catch(SQLException e2){
                                                System.out.println("##close.SQLException");
                                }
                        }
                }       
        }

这是我实现的代码,仅供参考,再次谢谢老师的帮助!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-2 04:30 , Processed in 0.072123 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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