日期:2014-05-17  浏览次数:20775 次

结果集为封装就直接执行finally了
Java code

debug调试出现了问题,执行到content=run.executeQuery();
时候直接跳到finally{}去了这是怎么回事?对结果集的封装根本没有执行。
try {
            //预编译
            run=link.prepareStatement(sql);
            //解释预编译
            run.setString(1, mcbm);
            run.setString(2, beginTime);
            run.setString(3, endTime);
            //获得结果集
            content=run.executeQuery();
            //对结果集封装
            if(content.next()){
                while(content.next()){
                    //结果集封装到实体类
                    chd_Infobean=new CHD_Infobean();
                    chd_Infobean.setSeqno(content.getString("djbh"));
                    chd_Infobean.setCh_sum(content.getString("bdzje"));
                    chd_Infobean.setSp_num(content.getString("bdzs"));
                    System.out.println("单据编号:"+chd_Infobean.getSeqno()+"总金额:"+chd_Infobean.getCh_sum()+"总数:"+chd_Infobean.getSp_num());
                    //实体类封装到集合
                    chd_InfoArray.add(chd_Infobean);
                }
                
            }else{
                return chd_InfoArray;
            }
        } catch (Exception e) {
            // TODO: handle exception
        }finally{
            DBConn.closeLink(link, run, content);
        }



------解决方案--------------------
如果没有记录,那么不会走到if里

如果有一条记录,只会走到if里,不会走到while里

有两条记录才会走到while里


你干嘛加个if content.next()的判断?!画蛇添足
------解决方案--------------------
里面没数据呗,而且if判断可以去了~