当前位置: 代码迷 >> Java Web开发 >> [求助] 帮忙看看这个错误大概是什么意思??
  详细解决方案

[求助] 帮忙看看这个错误大概是什么意思??

热度:209   发布时间:2007-03-18 22:52:20.0
[求助] 帮忙看看这个错误大概是什么意思??


偶是新手,刚看了点JSP的书
在测试数据库的时候出了这么一个错误信息,我实在看不懂错误是什么意思!!

有经验的朋友帮忙看看!!

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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

exception

org.apache.jasper.JasperException: Exception in JSP: /dbprogram.jsp:52

49: out.println("恭喜,表连接创建成功!");
50: %>
51:
52: <%
53: ResultSet RS= Stmt.executeQuery("SELECT * FROM EMPLOYEE WHERE eage<25"); /*连接到数据库中的表EMPLOYEE上*/
54: String tt; /**号表示选择表中所有的列*/
55: String link; /*若选择其中的某几列可以将*号换成列标号*/


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
org.apache.jsp.dbprogram_jsp._jspService(dbprogram_jsp.java:104)
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:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
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.23 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.23

搜索更多相关主题的帖子: 数据库  Exception  The  JSP  

----------------解决方案--------------------------------------------------------
没代码,看不懂!
----------------解决方案--------------------------------------------------------

好像是有空指针异常,看看连接有没有问题!!


----------------解决方案--------------------------------------------------------
不是好象,就是!!!不过没代码哪能找到错误!
----------------解决方案--------------------------------------------------------

谢谢各位!!
我没发现有空指针异常在程序哪个地方??
帮忙看一下
下面是代码:

<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<!--导入结束-->
<html>
<head>
<title>数据库连接实验</title>
</head>
<body>
<%
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:try";//“try”的意思就是与刚才设置的数据源名对应;
Connection Con = null;
Statement Stmt = null;
try
{
try /*加载驱动程序*/
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
out.print("Connect to Database error: " + e.getMessage());
}
try /*建立连接*/
{
Con = DriverManager.getConnection(sConnStr,"sa","");
}
catch(SQLException e)
{
out.print(e.toString());
}

Stmt = Con.createStatement(); /*创建JDBC声明*/
String query="CREATE TABLE GUEST" + /*在数据库中创建新的表*/
"(NUM VARCHAR(32),"+
"USERNAME TEXT,"+
"CONTENT TEXT,"+
"PASSWORD INTEGER,"+
"TOTAL INTEGER,"+
"REALNAME TEXT)";
Stmt.executeUpdate(query); /*更新数据库*/
}
catch (Exception e) {}
out.println("恭喜,表连接创建成功!");
%>

<%
ResultSet RS= Stmt.executeQuery("SELECT * FROM EMPLOYEE WHERE eage<25"); /*连接到数据库中的表EMPLOYEE上*/
String tt; /**号表示选择表中所有的列*/
String link; /*若选择其中的某几列可以将*号换成列标号*/
String makeStr; /*WHERE语句表示条件选择*/
out.print("<table border=2 style=color:blue >");
while (RS.next()) {
out.print("<tr><td>");
tt = RS.getString("ename"); /*查询表中NUM字段的内容,字段内容可能使数组,默认列输出*/
out.print(tt);
out.print("</td><td>");
tt = RS.getString("esex");
out.print(tt);
out.print("</td><td>");
tt = RS.getString("eage");
out.print(tt);
out.print("</td><td>");
tt=RS.getString("egrade");
out.print(tt);
out.print("</td><td>");
}
out.print("</table>");
RS.close();
out.println("数据查询成功!");
%>

<% /*在数据库中添加数据*/
String sql="INSERT INTO EMPLOYEE VALUES ('5','aaa','m',54,'hehe')";
Stmt.executeUpdate(sql);
out.println("添加数据成功!");
%>
</body>
</html>


----------------解决方案--------------------------------------------------------
Exception in JSP: /dbprogram.jsp:52

这个代码的第52行

你自己看看是什么
----------------解决方案--------------------------------------------------------

 代码52行是红色的部分,我还是没看懂是什么问题

<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<!--导入结束-->
<html>
<head>
<title>数据库连接实验</title>
</head>
<body>
<%
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:try";//“try”的意思就是与刚才设置的数据源名对应;
Connection Con = null;
Statement Stmt = null;
try
{
try /*加载驱动程序*/
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
out.print("Connect to Database error: " + e.getMessage());
}
try /*建立连接*/
{
Con = DriverManager.getConnection(sConnStr,"sa","");
}
catch(SQLException e)
{
out.print(e.toString());
}

Stmt = Con.createStatement(); /*创建JDBC声明*/
String query="CREATE TABLE GUEST" + /*在数据库中创建新的表*/
"(NUM VARCHAR(32),"+
"USERNAME TEXT,"+
"CONTENT TEXT,"+
"PASSWORD INTEGER,"+
"TOTAL INTEGER,"+
"REALNAME TEXT)";
Stmt.executeUpdate(query); /*更新数据库*/
}
catch (Exception e) {}
out.println("恭喜,表连接创建成功!");
%>

<%
ResultSet RS= Stmt.executeQuery("SELECT * FROM EMPLOYEE WHERE eage<25"); /*连接到数据库中的表EMPLOYEE上*/

String tt; /**号表示选择表中所有的列*/
String link; /*若选择其中的某几列可以将*号换成列标号*/
String makeStr; /*WHERE语句表示条件选择*/
out.print("<table border=2 style=color:blue >");
while (RS.next()) {
out.print("<tr><td>");
tt = RS.getString("ename"); /*查询表中NUM字段的内容,字段内容可能使数组,默认列输出*/
out.print(tt);
out.print("</td><td>");
tt = RS.getString("esex");
out.print(tt);
out.print("</td><td>");
tt = RS.getString("eage");
out.print(tt);
out.print("</td><td>");
tt=RS.getString("egrade");
out.print(tt);
out.print("</td><td>");
}
out.print("</table>");
RS.close();
out.println("数据查询成功!");
%>

<% /*在数据库中添加数据*/
String sql="INSERT INTO EMPLOYEE VALUES ('5','aaa','m',54,'hehe')";
Stmt.executeUpdate(sql);
out.println("添加数据成功!");
%>
</body>
</html>


----------------解决方案--------------------------------------------------------
ResultSet RS= Stmt.executeQuery("SELECT * FROM EMPLOYEE WHERE eage<25");
先确保你的stmt对象是否已存在,否则他是个NULL值。你先看看你上面的Stmt = Con.createStatement()是否建立
----------------解决方案--------------------------------------------------------

谢谢!
真的有点烦!!
我把数据库的设置改了一下!配置数据源的时候采用的是Windows身份认证了
Con = DriverManager.getConnection(sConnStr,"sa",""); 也改为了
Con = DriverManager.getConnection(sConnStr);


改后的代码如下:

<%@ page contentType="text/html; charset=gb2312" %>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<!--导入结束-->
<html>
<head>
<title>数据库连接实验</title>
</head>
<body>
<%
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:try";//“try”的意思就是与刚才设置的数据源名对应;
Connection Con = null;
Statement Stmt = null;
try
{
try /*加载驱动程序*/
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
out.print("Connect to Database error: " + e.getMessage());
}
try /*建立连接*/
{
Con = DriverManager.getConnection(sConnStr); /*代码修改的地方*/
}
catch(SQLException e)
{
out.print(e.toString());
}

Stmt = Con.createStatement(); /*创建JDBC声明*/
String query="CREATE TABLE GUEST" + /*在数据库中创建新的表*/
"(NUM VARCHAR(32),"+
"USERNAME TEXT,"+
"CONTENT TEXT,"+
"PASSWORD INTEGER,"+
"TOTAL INTEGER,"+
"REALNAME TEXT)";
Stmt.executeUpdate(query); /*更新数据库*/
}
catch (Exception e) {}
out.println("恭喜,表连接创建成功!");
%>

<%
ResultSet RS= Stmt.executeQuery("SELECT * FROM EMPLOYEE WHERE eage<25"); /*连接到数据库中的表EMPLOYEE上*/
String tt; /**号表示选择表中所有的列*/
String link; /*若选择其中的某几列可以将*号换成列标号*/
String makeStr; /*WHERE语句表示条件选择*/
out.print("<table border=2 style=color:blue >");
while (RS.next()) {
out.print("<tr><td>");
tt = RS.getString("ename"); /*查询表中NUM字段的内容,字段内容可能使数组,默认列输出*/
out.print(tt);
out.print("</td><td>");
tt = RS.getString("esex");
out.print(tt);
out.print("</td><td>");
tt = RS.getString("eage");
out.print(tt);
out.print("</td><td>");
tt=RS.getString("egrade");
out.print(tt);
out.print("</td><td>");
}
out.print("</table>");
RS.close();
out.println("数据查询成功!");
%>

<% /*在数据库中添加数据*/
String sql="INSERT INTO EMPLOYEE VALUES ('5','aaa','m',54,'hehe')";
Stmt.executeUpdate(sql);
out.println("添加数据成功!");
%>
</body>
</html>


现在出的错误变成这样的了:

HTTP Status 500 -

--------------------------------------------------------------------------------

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:476)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
org.apache.jsp.dbprogram_jsp._jspService(dbprogram_jsp.java:104)
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:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
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.23 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.23


劳驾帮忙看看这错误又是什么意思呢???  还是空指针??
如果是空指针,那又是哪行代码了呢??


----------------解决方案--------------------------------------------------------
还是空指针异常,其实空指针异常是最好排除的,无非就是保证你所用到的对象都不是null就可以了

你可以在你每生成一个对象的时候,用System.out.println来输出一下,看看它是不是 null的就知道在那里哪个对象被赋了null了
----------------解决方案--------------------------------------------------------
  相关解决方案