★★tomcat5.0.19+Oracle9.2+j2sdk1.4.2下,连接池配置问题★★

andraw2002 2004-09-04 05:23:07
环境:Windows2000+Oracle9.2+j2sdk1.4.2+tomcat5.0.19
我已经把Oracle的驱动程序classes12.jar放到了:%CATALINA_HOME%\common\lib\下面,并且我通过下面的代码能够正常的访问数据库:
<%@ page contentType="text/html; charset=GB2312" language="java" %>
<%@ page import="java.sql.*" %>
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@10.0.0.15:1521:pxzx";
String uid = "szbd";
String pwd = "szbd911";
Connection conn = DriverManager.getConnection(url, uid, pwd);

Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select * from fmsb where id<=1000 order by id");

//输出数据

rs.close();
stmt.close();
conn.close();
%>
==============================
现在我使用连接池来做,修改%CATALINA_HOME%\conf\server.xml(部分如下:)
<GlobalNamingResources>

<!-- Test entry for demonstration purposes -->
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>

<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved">
</Resource>
<ResourceParams name="UserDatabase">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>

<Resource name="jdbc/oracle" auth="Container"
type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/oracle">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@10.0.0.15:1521:pxzx</value>
</parameter>
<parameter>
<name>username</name>
<value>szbd</value>
</parameter>
<parameter>
<name>password</name>
<value>szbd911</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>

</GlobalNamingResources>
在%CATALINA_HOME%\conf\web.xml增加如下内容:
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/oracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
===========================
...全文
170 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
andraw2002 2004-11-09
  • 打赏
  • 举报
回复
至今还是搞不懂,郁闷,再想其它的办法吧,今天结帖……
andraw2002 2004-09-06
  • 打赏
  • 举报
回复
问题还是存在:
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)
vcvj 2004-09-06
  • 打赏
  • 举报
回复
try using snippet below:
static String jndiName="jdbc/oracle";
public static Connection getConnection() throws Exception{
Connection conn = null;
try {
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
Object obj = (Object) ctx.lookup(jndiName);
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
conn= ds.getConnection();
andraw2002 2004-09-06
  • 打赏
  • 举报
回复
IP"10.0.0.15"我本机的IP,而且不是动态的
朋友别哭 2004-09-04
  • 打赏
  • 举报
回复
up
kui 2004-09-04
  • 打赏
  • 举报
回复
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@10.0.0.15:1521:pxzx</value>
</parameter>

这个IP"10.0.0.15"是否正确?如果不是本机服务器,看本机与服务器的连接通不?

如果是本地服务器,对于设置了动态IP地址的PC,如果网络不通,则应设置一个静态的IP地址,IP这里可用localhost。对于静态的IP地址,如果网络不通,网关一项的设置对连接有影响。
andraw2002 2004-09-04
  • 打赏
  • 举报
回复
现在我把访问数据库的页面改为:
<%@ page contentType="text/html; charset=GB2312" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.DataSource, javax.naming.Context, javax.naming.InitialContext" %>
<%@ page import="oracle.jdbc.pool.*"%>
<%
Context env = (Context) new InitialContext();
DataSource PoolConn = (DataSource) env.lookup("java:comp/env/jdbc/oracle");
Connection Conn=PoolConn.getConnection();
Statement Stmt=Conn.createStatement();
.......
%>
程序执行到:Connection Conn=PoolConn.getConnection();的时候就出现了如下的错误:
exception

javax.servlet.ServletException: Cannot create JDBC driver of class '' for connect URL 'null', cause: null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.index_jsp._jspService(index_jsp.java:108)
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)

root cause

org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null', cause: null
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:750)
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:518)
org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
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)

==========================
小弟我刚学习,请各位大侠帮忙!!!!!

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧