通过数据库验证登陆出这个错, 是什么意思
public class EmpDAO {
//验证用户
public int verify(Employee Emp){
int uid=-1;
Connection con=null;
PreparedStatement pStmt=null;
ResultSet res=null;
String strSql;
try {
con=DBcon.getConnection();
strSql="select top 1 * from employee where name=?"
+"and password ?";
pStmt=con.prepareStatement(strSql);
pStmt.setString(1, Emp.getName());
pStmt.setString(2,Emp.getPassword());
res=pStmt.executeQuery();
if(res.next()) uid=res.getInt("employee_id");
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBcon.closeResultSet(res);
DBcon.closeStatement(pStmt);
DBcon.closeConnection(con);
}
return uid;
}
}
servlet的都post方法:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws
ServletException,
IOException {
HttpSession session=request.getSession();
String uname=request.getParameter("uName");
String upassword=request.getParameter("password");
Employee Emp=new Employee();
Emp.setName(uname);
Emp.setPassword(upassword);
EmpDAO Empdao=new EmpDAO();
int uid=Empdao.verify(Emp);
if(uid==-1){
response.sendRedirect("Login.jsp");
}else{
session.setAttribute("LONGIN_USER", uid);
request.getRequestDispatcher("vetSerach.jsp").forward(request,response);
}
错误信息是:
type Exception report
message
description
The server encountered an internal error () that prevented it from fulfilling this request.exception
java.lang.NullPointerException DAO.EmpDAO.verify(EmpDAO.java:19)
MyServlet.EmpServlet.doPost(EmpServlet.java:44)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
好像是那个sql语句的错误
但不知道怎么搞啊
求大神知道
------解决方案--------------------
Java code
strSql="select top 1 * from employee where name=?"
+" and password=?";
------解决方案--------------------
Java code
if(res.next()) uid=res.getInt("employee_id");
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html