您的位置:首页 > 运维架构 > Tomcat

使用JNDI进行Tomcat 5.5.17和MySQL连接池的配置

2006-10-10 22:26 471 查看
说明一下步骤:

一、修改server.xml文件

<Resource
name="jdbc/testA"
type="javax.sql.DataSource"
auth="Container"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/testA"
maxActive="4"/>

<Resource
name="jdbc/testB"
type="javax.sql.DataSource"

auth="Container"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/testB"
maxActive="4"/>


PS.有多个JNDI就添加多个


二、在%TOMCAT_HOME%/conf/Catalina/localhost下新建一个与你项目文件夹同名的xml文件

例如:我的项目名为testJNDI,那就创建一个testJNDI.xml的文件。内容为:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/testA"
type="javax.sql.DataSource"

auth="Container"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/testA"
maxActive="4"/>

<Resource
name="jdbc/testB"
type="javax.sql.DataSource"

auth="Container"
password="123456"
driverClassName="com.mysql.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/testB"
maxActive="4"/>

</Context>
PS.其实Resource的内容和server.xml的一致。注意,要是这错误的话,会抛出错误

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'


三、修改%TOMCAT_HOME%/webapps/yourweb/WEB-INF下的web.xml文件

在</web-app>之前添加:

<resource-ref>

<description>mysql JNDI</description>

<res-ref-name>jdbc/testA</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

<resource-ref>

<description>mysql JNDI</description>

<res-ref-name>jdbc/testA</res-ref-name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

PS.有多个就添加多个
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: