集合报
空指针 当集合为空时怎么样让程序继续正确运行
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集合为空 就不让它继续往下走 感觉对着 但为什么一直报空指针
------解决方案--------------------
首先如果dbmanager为空,,那么RecordSet rs1=dbmanager.select(sql); 这句无论如何都会报空指针。。。
保证了dbmanager不为空,然后判断rs1!=null
while(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));
}
}