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);
        }

解决方案 »

  1.   

    如果没有记录,那么不会走到if里如果有一条记录,只会走到if里,不会走到while里有两条记录才会走到while里
    你干嘛加个if content.next()的判断?!画蛇添足
      

  2.   

    假设结果集的记录足够的话,
    if(content.next()){   游标指向第一条记录
    while(content.next()){   每执行一次,游标向下移动一位
    你的程序没有封装结果集,说明你的结果集最多只有一条,如楼上说的,只会走到if里,不会走到while里再如楼上说的,别加个if(content.next()){ ...这个next()不能乱用啊,用一次游标往下移动一位啊
    所以直接while(content.next()){ 从第一条记录开始循环就可以了
      

  3.   

    哪个if判断确实画蛇添足,错误我改过来,关键是为什么我在数据库中查询有十几条记录,但是在这边我做了个
    content=run.executeQuery();
    content.last();
    int row=content.getRow();
    System.out.println("结果集行数:"+row);
    content.beforeFirst();row竟然是0,是sql语句的问题吗?还是别的原因?