java从mysql查询返回时出现空指针异常
控制器类调用:
List<FOO> fooList = fooDao.getFooList(String.valueOf(branchId),customerId,String.valueOf(systemIndex));
被调用的Dao类方法:
public List<FOO> getFooList(String index_branch,String index_cust,String index_sys)
{
// Object[] helo= new Object[10];
System.out.println("branchId -> " +index_branch+ "customerId -> " +index_cust+ " systemId -> " +index_sys);
return db.query("select * from tb_foo where branch=? and customer=? and system=?",new RowMapper<FOO>() {
@Override
public FOO mapRow(ResultSet rs, int i) throws SQLException {
FOO foo = new FOO();
foo.setPi(rs.getInt("foo_pi"));
foo.setIndex(rs.getInt("foo_index"));
foo.setFooName(rs.getString("foo_name"));
foo.setFooValue(""+rs.getInt("foo_value"));
return foo;
}
},index_branch,index_cust,index_sys);
}
当使用CommandLine
客户机提供查询时,会从数据库返回一个值列表,但是RowMapper
不会返回。我检查了fooDao是否返回null,但它没有。在return db.query(...);
行上获取null指针异常
# 1 楼答案
不确定你的问题到底是什么但是
在
处放置一个断点,并检查db是否为空