我在调试一个系统中,把在别的机器上演示好的系统直接放到tomcat的webapps下,把数据库导入mysql,在登录的时候出现java.lang.NullPointerException错误,提醒是DBOperation.java文件的64行出错,可是64行是this.rs.close();this.stmt.close();,这个没错啊。
附错误代码
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
hospital.db.dboperation.DBOperation.closeConnection(dboperation.java:64)
org.apache.jsp.patient.register_jsp._jspService(register_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
还有DBOperation文件
package hospital.db.dboperation;
import java.sql.*;
import hospital.db.dboperation.*;
import hospital.db.*;
/**
* 抽象类,用以封装子类需要用到的数据库操作对象和方法
*
*/
abstract class DBOperation{
protected Statement stmt;
protected ResultSet rs;
protected ResultSet result;
protected String strSQL;
protected String id;
protected Connection conn;
/**
* 构造器
*
* 参数:
* id-用户ID
*/
protected DBOperation(String id)
throws InvalidUserException{
this.id=id;
this.result=null;
try{
this.checkUser(id);
}
catch(InvalidUserException iue){
throw iue;
}
}
/**
* 返回数据集
*
* 返回值-数据集对象
*/
public ResultSet getResultSet(){
return result;
}
/**
* 用户登录,需要子类实现
*
* 参数:
* password-密码
*
* 返回值-操作结果代码
*/
protected abstract int login(String password);
/**
* 关闭数据库连接
*/
public void closeConnection(){
try{
this.rs.close();
this.stmt.close();
}
catch(SQLException sqle){
Debug.log(Debug.getExceptionMsg(sqle));
}
}
/**
* 查询用户名合法性,需要子类实现
*
* 参数:
* id-用户标识符
*/
protected abstract void checkUser(String id)
throws InvalidUserException;
}