我得数据库连接池怎么建立不成功啊?我是按照csdn上文档说的方法做的啊,希望大侠解决,立马给分啊!

liuxianguo964 2004-09-11 06:13:23
我得数据库连接池怎么建立不成功啊?我是按照csdn上文档说的方法做的啊,希望大侠解决,立马给分啊!
web server:Apache Tomcat/5.0.16
database: Oracle 9i

server.xml文件内容如下
---------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<Server>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>

<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>
<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>
</GlobalNamingResources>
<Service name="Catalina">
<Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="8080" redirectPort="8443">
</Connector>
<Connector port="8009" protocol="AJP/1.3" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" redirectPort="8443">
</Connector>
<Connector address="dean" enableLookups="true" port="80" redirectPort="8000">
</Connector>
<Engine defaultHost="localhost" name="Catalina">
<Host appBase="webapps" name="localhost">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
</Host>
<Host appBase="webapps" name="dean">
</Host>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
</Engine>
</Service>


<Context displayName="My Web Application" docBase="myapp" path="/myapp" reloadable="true">
<Resource name="jdbc/wapOracle" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/wapOracle">
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@10.10.1.2:1521:orcl</value>
</parameter>
<parameter>
<name>password</name>
<value>rs</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>rs</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>
</ResourceParams>
</Context>


</Server>
-------------------------------------------
...全文
206 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yangbc 2004-12-27
搂主是垃圾,别人好心回答你,看你这个熊样
回复
zhaoqiubo 2004-09-13
我配置连接池的时候,没有你这么麻烦。我就配置了server.xml这个文件啊。别的都没有,可是我的还是好用的呀。
而且tomcat自带的doc中有关于dbcp连接池的配置文档,并且有oracle的实例,你可以去看看的.
回复
jiankou2001 2004-09-13
请文明用语!
回复
liuxianguo964 2004-09-13
不用连接池看看,
是不是由于没有找到驱动
废话啊,当然可以啊,你没听我说:“找不到连接池吗?”你们这些人真恶心,题目不看清就瞎说
回复
opencsdn 2004-09-12
不用连接池看看,
是不是由于没有找到驱动
回复
caoxmby 2004-09-12
我也碰到过类似的问题:
当时就是在图形界面中配置后取不到连接池,但我把手动在context元素中配置后就好了。
我跟踪过错误,发现在取连接的时候,配置的driverClassName都成null了。
回复
liuxianguo964 2004-09-11
myapp.xml文件内容,这是我的目录的配置文件
-------------------------------------------
<Context displayName="My Web Application" docBase="myapp" path="/myapp">
<Resource name="jdbc/wapOracle" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/wapOracle">
<parameter>
<name>url</name>
<value>jdbc:oracle:thin:@10.10.1.2:1521:orcl</value>
</parameter>
<parameter>
<name>password</name>
<value>rs</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>rs</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>


</ResourceParams>

</Context>
------------------------------------------------
web.xml 是myapp目录下的WEB-INF子目录下的
------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>My Web Application</display-name>
<description>
A application for test.
</description>

<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/wapOracle</res-ref-name> <!--这里name的值也必须与server.xml中的Resource里的name的值相同-->
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<servlet>
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet>
<servlet-name>requestInfoExample</servlet-name>
<display-name>RequestInfoExample</display-name>
<description>A test Servlet</description>
<servlet-class>RequestInfoExample</servlet-class>
</servlet>
<servlet>
<servlet-name>RequestInfo</servlet-name>
<display-name>RequestInfo</display-name>
<description>A test Servlet</description>
<servlet-class>RequestInfo</servlet-class>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>chat.LoginConfirmServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>addContent</servlet-name>
<servlet-class>chat.AddContentServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>intsservlet</servlet-name>
<servlet-class>IntsServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>requestParamExample</servlet-name>
<servlet-class>RequestParamExample</servlet-class>
</servlet>
<servlet>
<servlet-name>dataStreamEcho</servlet-name>
<servlet-class>DataStreamEcho</servlet-class>
</servlet>



<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/servlet/Test</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>requestInfoExample</servlet-name>
<url-pattern>/requestInfoExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>RequestInfo</servlet-name>
<url-pattern>/servlet/RequestInfo</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>addContent</servlet-name>
<url-pattern>/addContent</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>intsservlet</servlet-name>
<url-pattern>/servlet/intsservlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>requestParamExample</servlet-name>
<url-pattern>/requestParamExample</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dataStreamEcho</servlet-name>
<url-pattern>/servlet/dataStreamEcho</url-pattern>
</servlet-mapping>


</web-app>
--------------------------------------------------
我显示通过http://localhost:8080/admin 通过图形化界面设置的,结果不行,所以后来把myapp.xml文件内容在server.xml文件
里又写了一遍,不知道是不是位置放的不对还是什么原因,报错还是找不到cannot get Connection pool.
我的测试文件如下
------------------------------
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import= "java.sql.* "%>
<%@ page import= "javax.naming.* "%>
<%!
ResultSet rs=null;
%>
<%
try{
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env"); //获取连接池对象
Object obj = (Object) ctx.lookup("jdbc/wapOracle"); //类型转换
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = "select * from RS_USERS";
stmt.executeQuery(strSql);
if(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
}
catch(Exception ex)
{
ex.printStackTrace();
throw new SQLException("cannot get Connection pool.");
}
%>
<hr>
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-11 06:13
社区公告
暂无公告