分页时候出现空指针错误
我在分页从数据库取数据的时候出现空指针错误,初步定位是sql语句搞的鬼,调用方法是,打印pageNo能打印具体的数值,但当它出现在sql语句中时侯就无法取出数据,sql语句中用具体数值是能取出来的,哪位高手帮我看看,代码如下:
public List<Product> getProducts(int pageNo, int pageSize) {
Connection conn=null;
ResultSet rs=null;
List<Product> list=new ArrayList<Product>();
try {
conn=DB.getConn();
System.out.println(pageNo);
String sql="select * from product"+pageNo+","+pageSize; rs=DB.executeQuery(conn,sql);
while(rs.next()){
Product p=new Product();
p.setId(rs.getInt("id"));
p.setName(rs.getString("name"));
p.setDescr(rs.getString("descr"));
p.setNormalPrice(rs.getDouble("normalPrice"));
p.setMemberPrice(rs.getDouble("memberprice"));
p.setPdate(rs.getTimestamp("Pdate"));
p.setCategoryId(rs.getInt("categoryId"));
list.add(p);
}
} catch (SQLException e){
e.printStackTrace();
} finally {
DB.closeRs(rs);
DB.closeConn(conn);
}
return list;
}