String sql = "select * from user where type = 5 and passwordquest in(select companyId from companyRight where companyId in(select id from user where type = 2 and netmoney>0)) and birthMessageStatus<>1";
//查询用户
RecordSet rs1=dbmanager.select(sql);        这行在运行时是空的,我就要的是空
while(rs1.next()){
users= new UserForm();
users.setId(rs1.getInt("id"));
users.setName(rs1.getString("name"));
users.setLoginName(rs1.getString("loginName"));
users.setPasswordquest(rs1.getInt("passwordquest"));
users.setGender(rs1.getString("gender"));
users.setQq(rs1.getString("Qq"));
users.setDateOfBirth(rs1.getString("dateOfBirth").substring(5));
}
}
return users;
如果rs1集合为空 就不让它继续往下走 感觉对着 但为什么一直报空指针

解决方案 »

  1.   

     = =。。捕获异常。或者加判断是否为null
      

  2.   

    因为rs1为null,当null.next的时候,是肯定会报空指针异常的。那么你在if(rs1.next){。}就没有意义了。最好在if(rs1.next){。}外层再加个rs1是否为空的判断!
      

  3.   

    if(rs1!=null){
    while(...){
    }
    }else{
    ...
    }
      

  4.   

    首先如果dbmanager为空,,那么RecordSet rs1=dbmanager.select(sql); 这句无论如何都会报空指针
    保证了dbmanager不为空,然后判断rs1!=nullwhile(rs1!=null && rs1.next()){
    users= new UserForm();
    users.setId(rs1.getInt("id"));
    users.setName(rs1.getString("name"));
    users.setLoginName(rs1.getString("loginName"));
    users.setPasswordquest(rs1.getInt("passwordquest"));
    users.setGender(rs1.getString("gender"));
    users.setQq(rs1.getString("Qq"));
    users.setDateOfBirth(rs1.getString("dateOfBirth").substring(5));

    }
      

  5.   

    RecordSet rs1=dbmanager.select(sql); 这行在运行时是空的,我就要的是空
    if (rs1 == null) return null;
    ...
      

  6.   

    数据信息 先检查 在判断 if(!=null){while(.next()){
    }}