配置tomcat数据池一般在全局与局部两种配置方式,由于全局配置后的WEB项目移植性不好,所以建议使用局部方式来配置。
在你想要使用tomcat 连接池的项目中的web.xml文件中添加如下内容:
<resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/mysql</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
其中你需要根据自己的实际修改一下<res-ref-name>的内容,
然后在META-INF文件夹下创建一个content.xml文件,加入如下内容:
<Context reloadable="true"> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="4" maxIdle="10" maxWait="100000" username="root" password="admin" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/yourdatabasename" /> </Context>
其它的不用多说,这个地方注意<Resource name=...../> 此处的name与web.xml文件中的<res-ref-name>对应,这样整个连接池配置过程中结束 了。但注意tomcat连接池只能在tomcat上运行,脱离tomcat则无法运行.
另外,一定要将mysql的数据库驱动放在tomcat服务器上,仅包含在项目中是不行的.