Tomcat与MySQL用连接池的方式连接,好处就不说了,重点说一个个人的环境配置心得……
在网上可以搜索到很多种方式,但是有些方式不一定能够成功。下面说一下我的方式,绝对测试通过。
(环境:Tomcat 6.0+MySQL 5.1.49-community +Eclipse 3.6)
在META-INF文件夹下新建一个context.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Context path="/项目名/jsp文件所在文件夹/..."docBase="/项目名/...">
<Resource name="jdbc/sample" auth="Container" type="javax.sql.DataSource"
username="admin"
password="admin"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test"/>
</Context>
如果需要多个连接信息,在<Context></Context>之中继续添加<Resource.../>元素即可
然后在/WEN-INF/web.xml文件中添加
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/sample</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
就这样,配置完成了,其它细节这里就不说了,网上到处都是的……