tomcat连接jsp文件出错。我找了很久,不知道错误在哪。

这是什么问题呢?大家帮忙解决一下。[code="java"]type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException
com.tools.ConnDB.executeQuery(ConnDB.java:55)
com.dao.ScripDao.query(ScripDao.java:25)
com.action.ScripAction.scripQuery(ScripAction.java:43)
com.action.ScripAction.execute(ScripAction.java:26)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

[/code]

12个回答

试试,看哪一行为空?
[code="java"] public ResultSet executeQuery(String sql) {
try { // 捕捉异常
conn = getConnection();
System.out.println("conn:"+conn);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
System.out.println("stmt:"+stmt);
rs = stmt.executeQuery(sql);
System.out.println("rs:"+rs);
} catch (SQLException ex) {
System.err.println(ex.getMessage()); // 输出异常信息
}
return rs; // 返回结果集对象
}
[/code]

com.tools.ConnDB.executeQuery(ConnDB.java:55)

把这个方法代码贴出来,

在这个办法当中com.tools.ConnDB.executeQuery有问题,查询ConnDB类55行是写什么,最好是把executeQuery贴出来。

[code="java"]com.tools.ConnDB.executeQuery(ConnDB.java:55) [/code]
[color=blue][b]
这一句代码,报空指针了。检查该句代码,或者Debug跟踪到此,看看哪一个变量是空的[/b][/color]

应该是这里getConnection is null

[quote]调试不了 [/quote]

为什么??什么状况?

你先能正常获取getConnection。你这段代码差不多跟我写的一样啊。[code="java"]
/**
* 查询一(普通-查询)
*/
public ResultSet executeQuery(String sql) throws Exception{
sql = sql.toLowerCase();
ResultSet rs = null;
PreparedStatement prstmt = null;
Connection conn = null;
try{
conn = getConnection();
if(conn!=null){
prstmt = conn.prepareStatement(sql);
rs = prstmt.executeQuery();

conn.close();
}
}catch(Exception e){
e.printStackTrace();
if(conn!=null){
conn.close();
}
}
return rs;
}
[/code]
我的写法

[quote]1.java.lang.NullPointerException

2. com.dao.ScripDao.query(ScripDao.java:27) [/quote]
贴出代码

根据api的说明文档,可以看到
executeQuery返回值的说明,说明返回值永远不会为null
[quote]Returns:
a ResultSet object that contains the data produced by the given query; never null [/quote]

ResultSet 中next方法返回的类型为Boolean。永远不会为null
[quote]Returns:
true if the new current row is valid; false if there are no more rows [/quote]
再仔细检查错误所在。

你修改一下这段代码
[code="java"]
public ResultSet executeQuery(String sql) {

try { // 捕捉异常

conn = getConnection();

System.out.println("conn:"+conn);

stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_READ_ONLY);

System.out.println("stmt:"+stmt);

rs = stmt.executeQuery(sql);

System.out.println("rs:"+rs);

} catch (SQLException ex) {

System.err.println(ex.getMessage()); // 输出异常信息

}

return rs; // 返回结果集对象

}

[/code]
测试一下你这段代码
if(rs!=null&&rs.next()){
System.out.println("come on~~");
}

共12条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐