-----急急急!基础问题,各位应该可以解答!------

saper 2001-12-15 09:05:47
在windows2000下 安装了jdk1.3.1,tomcat3.2.3,设置如下:

-------------------------
path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;d:\jdk1.3.1\bin;

java_home=d:\jdk1.3.1

tomcat_home=d:\tomcat3.2.3

classpath=.;d:\jdk1.3.1\lib\dt.jar;d:\jdk1.3.1\lib\tools.jar;d:\tomcat3.2.3\servlet.jar;d:\tomcat3.2.3\webserver.jar;
--------------------------
test.jsp 放在 d:\tomcat3.2.3\webapps\ROOT\jsp\ 下 (jsp 目录为自己新建)

<HTML>
<head>
<meta http-equiv="Content-Type" conntent="text/html; charset=gb2312">
</head>
<BODY>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="sql_bean" scope="page" class="test.faq" />
<%
ResultSet rs=sql_bean.executeQuery("select * from forum_user");
while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");
}
rs.close();
%>
</BODY>
</HTML>

-----------------------------
javabean: faq.java编译后放在d:\tomcat3.2.3\webapps\WEB_INF\classes\test 下面


package test;

import java.io.*;
import java.sql.*;

public class faq {
String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:ex_user/ex_user@192.168.0.1:1521:oradb";
Connection conn=null ;
ResultSet rs=null;
public faq(){
try{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("faq():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}

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

运行 http://localhost:8081/jsp/test.jsp 出现以下错误:

javax.servlet.ServletException
......以下省略(太多了)

Root cause:
java.lang.NullPointerException
..........


------------------------------------
注:以上程序在JDeveloper中可以调试通过的





...全文
80 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
saper 2001-12-17
我解决了,原来是在Tomcat下找不到oracle dirver ,我设置了oracle dirver类路径后就好了,


谢谢各位了!
回复
saper 2001-12-17
To vdragon(紫龙):

应该不是你说的问题,我在JDeveloper中调试可以通过啊!

有如下错误:

Error: 500
Location: /jsp-test/jsp/faq-test.jsp
Internal Servlet Error:

javax.servlet.ServletException
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
at jsp_0002dtest.jsp._0002fjsp_0002dtest_0002fjsp_0002ffaq_0002dtest_0002ejspfaq_0002dtest_jsp_1._jspService(_0002fjsp_0002dtest_0002fjsp_0002ffaq_0002dtest_0002ejspfaq_0002dtest_jsp_1.java:105)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)

Root cause:
java.lang.NullPointerException
at jsp_0002dtest.jsp._0002fjsp_0002dtest_0002fjsp_0002ffaq_0002dtest_0002ejspfaq_0002dtest_jsp_1._jspService(_0002fjsp_0002dtest_0002fjsp_0002ffaq_0002dtest_0002ejspfaq_0002dtest_jsp_1.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)

回复
yuanzi 2001-12-17
这不就是为空的错误吗?你这样catch一下看结果怎样?
try{
while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");
}
}catch(Exceptione e){
out.println("saper错误一"+e.toString());
}
这样你看看!把那两行注释掉,不能说明 ResultSet rs=sql_bean.executeQuery("select * from forum_user");这一行返回的值是什么,如果是null,那么while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");就会报空异常了。
回复
vdragon 2001-12-17
难道是rs.getString(1)抛出了Exception?
是不是第一列的类型不是String,然后是null,在toString()的时候出现异常
回复
saper 2001-12-17
各位帮一下忙啊!
回复
saper 2001-12-17
我换了tomcat4.0 出现下面错识:java.lang.NullPointerException.......


******但是在JDeveloper下调试可以通过啊!******
回复
tehcon 2001-12-17
应该是rs==null;
你的推断有问题,ResultSet rs=sql_bean.executeQuery("select * from forum_user");执行不报错并不能说明数据库连接没问题,因为你在bean中把exception都catch了,如果出错,返回的就是null,不然你可以注释掉while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");
}
然后把rs打印出来看看
回复
saper 2001-12-16
To bookbobby: 大哥你的方法好像不灵啊! 再帮我想想!

To yuanzi(远子):"select * from forum_user " 返回不为空,数据库连接没问题的,
只是要原程序中把 while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");
}
这两行注释掉就没问题的,可见"ResultSet rs=sql_bean.executeQuery("select * from forum_user");"这句没问题(就说明数据连接没问题),再帮我想想!


谢谢两位!
回复
yuanzi 2001-12-15
这与.java文件好象没有关系吧~!
建议:
1。select * from forum_user 返回的结果是什么,是不是为空?
2. 将while(rs.next()){
out.println("<li>"+rs.getString(1)+"</li>");
}
这个放到try{}catch(Exception e){}里面调试,如果还不行,在对上一句进行类试处理。
3.检查是否能正确连到数据库。
4.祝你好运!
回复
bookbobby 2001-12-15

可以了吗?

/*--by bookbobby(书呆)-+
 |            |
 |  你说爱我只是习惯  |
 |  再也不是喜欢    |
 |  我给你的爱     |
 |  已不再温暖     |
 |            |
 +--by bookbobby(书呆)-*/
回复
bookbobby 2001-12-15
faq.java

放在tomcat3.2.3\classes\test下

应该就可以了
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-12-15 09:05
社区公告
暂无公告