我已将oracle的驱动程序classes12.jar放入了tomcat5.0下的自已的站点的WEB_INF/lib/下了,设置了环境变量,我的程序如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="javax.servlet.*" import="java.io.*" import="oracle.jdbc.driver.OracleDriver" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head><body>
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:hungyan";
String user="huangyan";
String password="xujing";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt;
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select xm from person_information");
while(rs.next()){%>
您的第一个字段内容为:<%=rs.getString("xm")%>
<%}%>
<%System.out.print("error");%>
<%rs.close();
stmt.close();
conn.close();
%></body>
</html>但有这样的错误:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.data_jsp._jspService(data_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
java.sql.DriverManager.getConnection(DriverManager.java:512)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.data_jsp._jspService(data_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.请教各位高手发生这样错误的原因
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="javax.servlet.*" import="java.io.*" import="oracle.jdbc.driver.OracleDriver" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head><body>
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:hungyan";
String user="huangyan";
String password="xujing";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt;
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select xm from person_information");
while(rs.next()){%>
您的第一个字段内容为:<%=rs.getString("xm")%>
<%}%>
<%System.out.print("error");%>
<%rs.close();
stmt.close();
conn.close();
%></body>
</html>但有这样的错误:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.data_jsp._jspService(data_jsp.java:88)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
java.sql.DriverManager.getConnection(DriverManager.java:512)
java.sql.DriverManager.getConnection(DriverManager.java:171)
org.apache.jsp.data_jsp._jspService(data_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.请教各位高手发生这样错误的原因
解决方案 »
- 截取部分页面代码,求助牛人!!!
- Linux下关于mysql驱动的解决
- 在线给分:web页面select下拉框中的数据哪里来的?
- mozilla 中浏览不到<OBJECT id=HTML data=editor/editor.html width=500 height=450 type=text/x-scriptlet></object>的内容
- 动态Form问题,如何配置验证请给一段好吗?【最好有解释谢谢!!】
- 谁能提供个OA办公自动化系统的JSP源码及相关资料呢?先送100分,给了再加
- bean问题?
- 使用kineditor在线编辑,保存到数据库中之后使用poi导出成word文档出错,望大神指教
- jsp+bean结构,需要发给客户试用,又怕客户请高手反编译
- 请问在resin中servlet的类文件放在哪里?
- FCKeditor在TOMCAT下总报错,请高手指点!
- 游戏的模拟器嵌套在页面上的问题---100分啊
public static Connection getConnection() {
Connection con = null;
String CLASSFORNAME = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@127.0.0.1:1521:mydb";//
String user = "dtsc";
String password = "dtsc";
try {
Class.forName(CLASSFORNAME).newInstance();
con = DriverManager.getConnection(url, user, password);
//Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch (Exception e) {
e.printStackTrace();
}
return con;
} //关闭链接
public void ClosePro() throws Exception {
DataBaseConnection.getConnection().close();
}
}
rs的getString()方法的参数是int型,是rs记录集的列数
可以把那段JAVA代码放在JAVA文件里,加一个main方法测试一下连接数据库是否正常
这里好像不用newInstance();吧,
建议楼主加个main函数测试一下.
您的第一个字段内容为:<%=rs.getString("xm")%>
<%}%>
<%System.out.print("error");%>在用rs.next()之前,要用rs.beforefirst();将rs 指针指到第一个结果集之前~~~
2。不需要引入import="javax.servlet.*" import="java.io.*" import="oracle.jdbc.driver.OracleDriver"
至于问题到底是在哪里,还是要写个try,把异常位置打印出来比较好