容器:Tomcat 5.5X
数据库:MySql5.0
主要涉及几个目录,几个文件,如下
* 以下配置根据自己实际情况修改~
__________________________
1 Tomcat 安装目录/conf下/server.xml
在server.xml中~在<Context>里添加
<Resource auth="Container" name="jdbc/pure" type="javax.sql.DataSource" username="root" password="5200" driverClassName="org.gjt.mm.mysql.Driver" maxIdle="2" maxWait="5000" url="jdbc:mysql://localhost:3306/pure" maxActive="4"/>
2 Tomcat 安装目录/conf/Catalina/localhost 下新建一个与你工程文件夹一样名字的xml
比如你webapps下的工程名为test,那么就在Tomcat 安装目录/conf/Catalina/localhost 新建一个text.xml ,加入内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/pure"
type="javax.sql.DataSource"
password="5200"
driverClassName="org.gjt.mm.mysql.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/pure"
maxActive="4"/>
<Context>
<Resource
name="jdbc/pure"
type="javax.sql.DataSource"
password="5200"
driverClassName="org.gjt.mm.mysql.Driver"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/pure"
maxActive="4"/>
</Context>
3 项目工程中的web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/pure</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/pure</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
__________________________________________
经常报的一些异常说以下
* Cannot create JDBC driver of class '' for connect URL 'null'
1 检查驱动放到tomcat 目录/conmm/lib 下没
2 检查server.xml正不正确~或者用了版本不同的配置方法,所以没认到
3 在
/conf/Catalina/localhost 新建了xml没~确认一下参数
* javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
1 直接确认是不是没有在web.xml加入相应内容
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/pure</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/pure</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
本文出自 “Pure 纯粹--热衷于技术..” 博客,请务必保留此出处http://973007.blog.51cto.com/100031/62943