jsp连接数据库空指针异常,找了很久实在找不到错误
Exceptionreportmessagejava.lang.NullPointerExceptiondescriptionTheserverencounteredan...
Exception report
message java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
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:728)
root cause
java.lang.NullPointerException
com.bdqn.dao.impl.BaseDao.quary(BaseDao.java:32)
com.bdqn.dao.impl.UserDaoImpl.findAll(UserDaoImpl.java:17)
org.apache.jsp.Show_jsp._jspService(Show_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.41 logs.
代码“问题”
public ResultSet quary(String sql,Object...objs){
try {
ps=getConnection().prepareStatement(sql);
for(int i = 0; i < objs.length; i++) {
if(objs[i] instanceof java.util.Date) {
Date date=(Date)objs[i];
ps.setObject(i+1, date.getTime());
}else{
ps.setObject(i + 1, objs[i]);
}
}
rs = ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ArrayList<User> findAll(){
ArrayList <User> al=new ArrayList<User>();
String sql="SELECT * FROM `user`";
super.getConnection();
// Object[] objs={};
ResultSet rs=super.quary(sql);
try {
while(rs.next()){
int id=rs.getInt("id");
String name=rs.getString("name");
Date date=rs.getDate("date");
int age=rs.getInt("age");
String email=rs.getString("email");
String pwd=rs.getString("pwd");
User us=new User(id, name, date, age, email, pwd);
al.add(us);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.closeall();
return al;
}
<%
UserDaoImpl udi = new UserDaoImpl();
ArrayList <User> al = udi.findAll();
for(User s:al){
%>
<tr>
<td><%=s.getId() %></td>
<td><%=s.getName() %></td>
<td><%=s.getDate() %></td>
<td><%=s.getAge() %></td>
<td><%=s.getEmail() %></td>
<td><%=s.getPwd() %></td>
<td><a href="update?id=<%=s.getId() %>">修改</a> <a href="del?id=<%=s.getId() %>">删除</a></td>
</tr>
<%
}
ps=getConnection().prepareStatement(sql)是第32行 展开
message java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
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:728)
root cause
java.lang.NullPointerException
com.bdqn.dao.impl.BaseDao.quary(BaseDao.java:32)
com.bdqn.dao.impl.UserDaoImpl.findAll(UserDaoImpl.java:17)
org.apache.jsp.Show_jsp._jspService(Show_jsp.java:92)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.41 logs.
代码“问题”
public ResultSet quary(String sql,Object...objs){
try {
ps=getConnection().prepareStatement(sql);
for(int i = 0; i < objs.length; i++) {
if(objs[i] instanceof java.util.Date) {
Date date=(Date)objs[i];
ps.setObject(i+1, date.getTime());
}else{
ps.setObject(i + 1, objs[i]);
}
}
rs = ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ArrayList<User> findAll(){
ArrayList <User> al=new ArrayList<User>();
String sql="SELECT * FROM `user`";
super.getConnection();
// Object[] objs={};
ResultSet rs=super.quary(sql);
try {
while(rs.next()){
int id=rs.getInt("id");
String name=rs.getString("name");
Date date=rs.getDate("date");
int age=rs.getInt("age");
String email=rs.getString("email");
String pwd=rs.getString("pwd");
User us=new User(id, name, date, age, email, pwd);
al.add(us);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.closeall();
return al;
}
<%
UserDaoImpl udi = new UserDaoImpl();
ArrayList <User> al = udi.findAll();
for(User s:al){
%>
<tr>
<td><%=s.getId() %></td>
<td><%=s.getName() %></td>
<td><%=s.getDate() %></td>
<td><%=s.getAge() %></td>
<td><%=s.getEmail() %></td>
<td><%=s.getPwd() %></td>
<td><a href="update?id=<%=s.getId() %>">修改</a> <a href="del?id=<%=s.getId() %>">删除</a></td>
</tr>
<%
}
ps=getConnection().prepareStatement(sql)是第32行 展开
3个回答
展开全部
不用说,这一定是你数据库里没用信息,才会这样的!
追问
确定数据库里面是有数据的。用测试类都可以读取,只是 用jsp就没值了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个看代码看不出来,除非我帮你远程看看
更多追问追答
追问
可以把全部代码发给你看看
追答
不用发给我
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询