DAO层有这样一个方法:
public String[] getOmcIpByCity(String city) throws DaoException {
// TODO Auto-generated method stub
Session session = getSession();
SQLQuery sqlQuery = session
.createSQLQuery("select distinct RELATED_OMC from CUST_VLR where CITY='"
+ city + "'"); Iterator iter = sqlQuery.list().iterator();
if (iter.hasNext()) {
String[] s = new String[sqlQuery.list().size()];
;
int index = 0; while (iter.hasNext()) {
s[index] = iter.next().toString();
index++;
} releaseSession(session);
return s;
}
return null;
}此方法SQL的意思是通过CITY来取CITY下面对应的RELATED_OMC。 碰到了一个空指针的问题,例如:
执行:select distinct RELATED_OMC from CUST_VLR where CITY='泰州';
数据库下查到的数据是:
1:null
2: 1.2.3.4
3: 5.3.6.9
这样的话,“s[index] = iter.next().toString();”这句话就报空指针了。 请问有什么解决方法,各位帮忙看看。
public String[] getOmcIpByCity(String city) throws DaoException {
// TODO Auto-generated method stub
Session session = getSession();
SQLQuery sqlQuery = session
.createSQLQuery("select distinct RELATED_OMC from CUST_VLR where CITY='"
+ city + "'"); Iterator iter = sqlQuery.list().iterator();
if (iter.hasNext()) {
String[] s = new String[sqlQuery.list().size()];
;
int index = 0; while (iter.hasNext()) {
s[index] = iter.next().toString();
index++;
} releaseSession(session);
return s;
}
return null;
}此方法SQL的意思是通过CITY来取CITY下面对应的RELATED_OMC。 碰到了一个空指针的问题,例如:
执行:select distinct RELATED_OMC from CUST_VLR where CITY='泰州';
数据库下查到的数据是:
1:null
2: 1.2.3.4
3: 5.3.6.9
这样的话,“s[index] = iter.next().toString();”这句话就报空指针了。 请问有什么解决方法,各位帮忙看看。
try{
s[index]=iter.next().toString();
}catch(NullPointerException e){
s[index]="";
}
s[index] = iter.next()==null?"":iter.next();