java.lang.NullPointerException
com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33)
com.eshore.service.ProductService.findAll(ProductService.java:36)
org.apache.jsp.product_005flist2_jsp._jspService(product_005flist2_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我是查询语句,JSP JDBC连接MYsql的,用DAO模式,
下面是报错里面这两句有问题的话的出处:
第一句:com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33)
public List findAll(String product_name) throws Exception{
List list = new ArrayList();
String sql = "select product_id,product_name,price,info from product";
if(product_name!=null&&!"".equals(product_name)){
sql = "select product_id,product_name,price,info from product where product_name like? ";
this.pstmt.setString(1,"%" + product_name + "%");
}
else {
this.pstmt = this.conn.prepareStatement(sql);
}
ResultSet rs = this.pstmt.executeQuery();
Product product = null;
while (rs.next()){
product = new Product();
product.setProduct_id(rs.getString(1));
product.setProduct_name(rs.getString(2));
product.setPrice(rs.getDouble(3));
product.setInfo(rs.getString(4));
list.add(product);
}
this.pstmt.close();
return list;
}
标的是:this.pstmt.setString(1,"%" + product_name + "%");这句
第二句:com.eshore.service.ProductService.findAll(ProductService.java:36)
public List findAll(String product_name) throws Exception{
List list = null;
try{
list = this.dao.findAll(product_name);
}
catch (Exception e){
throw e;
}
finally {
this.dbconn.close();
}
return list;
}
是里面的:list = this.dao.findAll(product_name);
在第二处可疑错中,我开始想是不是product_name是不是没判断非空,
加了if(product_name!=null&&!"".equals(product_name)){
变成: try{ if(product_name!=null&&!"".equals(product_name)){
list = this.dao.findAll(product_name);
}}
什么的还是报这个错:
java.lang.NullPointerException
com.eshore.dao.ProductDaoImpl.findAll(ProductDaoImpl.java:33)
com.eshore.service.ProductService.findAll(ProductService.java:36)