当前位置: 代码迷 >> Java Web开发 >> 连接Oracle时出现异常
  详细解决方案

连接Oracle时出现异常

热度:277   发布时间:2006-06-24 12:33:33.0
连接Oracle时出现异常

我用eclipse+myeclipse+tomcat建了3个文件,在Oracle中建了一个表,然后运行文件,但是连接Oracle时出现异常,
异常如下:

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.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


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


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

Apache Tomcat/5.0.12


我已将ojdbc14.jar放到了C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myjsp\WEB-INF\lib下;

C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib下,
可还是出现同样的异常,
是不是要配置环境变量,还是要在eclipse里添加、配置什么呢?

感激不尽!!

[此贴子已经被作者于2006-6-24 13:24:56编辑过]

搜索更多相关主题的帖子: Oracle  

----------------解决方案--------------------------------------------------------

下面是3个文件的代码,大家看看是哪里有错:
index:
<html>
<head>
<title>留言板</title>
</head>
<body bgcolor="#ccc231" vlink="#000000" alink="#666666">
<DIV align="center">
<p><FONT size="7">
<b><font size="+6"></font></b>
</FONT>
</p>
<FORM method="post" action="index.jsp">
<TABLE width="75%" align="center" border=1>
<TR>
<TD width="30%">
<div align="right">姓名:</div>
</TD>
<TD width="70%">
<INPUT type="text" name="name">
</TD>
</TR>
<TR>
<TD width="30%">
<DIV align="right">电子邮件:</DIV>
</TD>
<TD width="70%">
<INPUT type="text" name="email">
</TD>
</TR>
<TR>
<TD width="30%">
<div align="right" >个人主页地址:</div>
</TD>
<TD width="70%">
<TEXTAREA name="body" rows="5" cols="30"></TEXTAREA>
</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">&nbsp;</TD>
</TR>
<TR>
<TD width="30%">&nbsp;</TD>
<TD width="70%">
<TABLE width="75%">
<TR>
<TD>
<INPUT type="submit" name="send" value="提交">
</TD>
<TD>
<INPUT type="reset" name="reset" value="重置">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<hr>
</DIV>
</body>
</html>

index.jsp:
<html>
<head>
</head>
<body>
<%@ page language="java" import="java.sql.*;"%>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="sqlbean" class="hh.Sql_data" scope="session" />
<%! String name,email,url,body,sql;%>
<%
name=request.getParameter("name");
email=request.getParameter("email");
url=request.getParameter("url");
body=request.getParameter("body");
if(name!=""&&email!=""&&body!="")
{
sql="insert into guestbook (name,email,url,body) values ('"+name+"','"+email+"','"+url+"','"+body+"')";
sqlbean.executeInsert(sql);
}
else
{
out.print("<b><font color=red>Sorry,Please enter your name,email,and body!!!</font></b>");
}
%>
<%
ResultSet RScount=sqlbean.executeQuery("SELECT * FROM guestbook");
int i=0;
while(RScount.next())
{
i++;
}
%>
<%--<p><a name=see><b>Now,<%=RScount %>Records.</b></a></p> --%>
<p><b>现在有<%=i%>条记录</b></p>
<%
RScount.close();
i=0;
%>
<p>&nbsp;</p>
<%
ResultSet RS=sqlbean.executeQuery("select * from guestbook");
while(RS.next())
{
name=RS.getString("name");
email=RS.getString("email");
url=RS.getString("url");
body=RS.getString("body");
%>
<table border=1 width=80%>
<tr>
<TD width=30%>昵称:</TD><TD width=70%><%=name%></TD>
</tr>
<TR>
<TD width=30%>电子邮件:</TD><TD width=70%><a href="maito:<%=email%>"><%=email%></a></TD>
</TR>
<TR>
<TD width=30%>个人主页地址:</TD><TD width=70%><a href="<%=url%>"><%=url%></a></TD>
</TR>
<TR>
<TD width=30%>内容:</TD><TD width=70%><%=body%></TD>
</TR>
</table>
<hr>
<%
}
RS.close();
%>
</body>
</html>

package hh;
import java.sql.*;
public class Sql_data {

String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@aa-52:1521:Grace";
Connection conn=null;
ResultSet rs=null;
public Sql_data()
{
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e)
{
System.err.println("sql_data():"+e.getMessage());
}
}
public void executeInsert(String sql)
{

try
{
conn=DriverManager.getConnection(sConnStr,"syetem","ffffff");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.out.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(sConnStr,"system","ffffff");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeDelete(String sql)
{
try
{
conn=DriverManager.getConnection(sConnStr,"system","ffffff");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeDelete:"+ex.getMessage());
}
}

}

表:guestbook:
SQL> desc guestbook
名称 是否为空? 类型
----------------------------------------- -------- --------------------
NAME NOT NULL VARCHAR2(20)
EMAIL NOT NULL VARCHAR2(30)
URL VARCHAR2(50)
BODY VARCHAR2(200)


大家帮下忙啊

[此贴子已经被作者于2006-6-24 22:54:10编辑过]


----------------解决方案--------------------------------------------------------
找到了一个错误后,再次运行文件,现在又出现了另外的异常了:

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: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:561)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause

java.lang.NullPointerException
org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:1792)
org.apache.catalina.loader.WebappClassLoader.findResource(WebappClassLoader.java:944)
org.apache.catalina.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1161)
javax.xml.parsers.SecuritySupport12$4.run(SecuritySupport12.java:119)
java.security.AccessController.doPrivileged(Native Method)
javax.xml.parsers.SecuritySupport12.getResourceAsStream(SecuritySupport12.java:112)
javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:263)
javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:169)
javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:139)
org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:129)
org.apache.jasper.compiler.JspConfig.processWebDotXml(JspConfig.java:112)
org.apache.jasper.compiler.JspConfig.init(JspConfig.java:213)
org.apache.jasper.compiler.JspConfig.findJspProperty(JspConfig.java:229)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:207)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


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


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

Apache Tomcat/5.0.12


这是什么问题呢?
----------------解决方案--------------------------------------------------------

楼上的异常应该是一些很基本的异常吧
一个是JasperException: Unable to compile class for JSP
不能为JSP编译类异常,是不是你的JDK没有配置好?
二是NullPointerException
空指针异常,是不是你使用了没有初始化的对象


----------------解决方案--------------------------------------------------------

我到现在还没下载到一个完整的Oracle哭一下


----------------解决方案--------------------------------------------------------
大家帮忙看一下我的环境变量是否有问题:

用户变量:
classpath:
.;C:\Program Files\Java\jdk1.5.0_06\lib;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar;

JAVA_HOME:
C:\Program Files\Java\jdk1.5.0_06

path:
C:\Program Files\Java\jdk1.5.0_06\bin


系统变量:
path:
D:\oracle\ora92\bin;C:\Program Files\Java\jdk1.5.0_06\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
----------------解决方案--------------------------------------------------------
把环境变量改了之后,异常又变成这样:

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.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.lang.NullPointerException
org.apache.jsp.index_jsp._jspService(index_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

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


Apache Tomcat/5.0.12



这又是什么问题啊??

[此贴子已经被作者于2006-6-24 20:57:46编辑过]


----------------解决方案--------------------------------------------------------
你加javax.servlet.jar的包了吗?给工程!
----------------解决方案--------------------------------------------------------
现在没有异常了,但是却出现了一个我无法理解的错误,脑袋都想破了,也没解决得了:

就是那个javabean(Sql_data.java)中的public void executeInsert(String sql)
方法它不执行,每次运行文件时,MyEclipse的Console都显示信息:sql_data.executeUpdate:ORA-01017: invalid username/password; logon denied

可是,public ResultSet executeQuery(String sql)和public void executeDelete(String sql)的username/password 也都是"syetem","ffffff" 呀,却能够正常调用,这究竟是怎么回事呀??

愁死我了!

大家帮忙分析一下是哪里的问题呀,谢谢了!!


----------------解决方案--------------------------------------------------------
  相关解决方案