Controller 类调用:
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(...);
最佳答案
不确定您的问题实际上是什么,但是,
在
db.query(...);处放置断点并检查 db 是否不为 null
关于java - 从 mysql 查询返回时出现空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16559236/