Tomcat6.0连接池的配置

首先,打开Tomcat的根目录\conf中的文件context.xml  在<context></context> 中添加这样一段配置:

<Resource

name = "jdbc/mysql"

auth="Container"

type="javax.sql.DataSource"

maxActive="100"

maxIdle="30"

maxWait="1000"

username="root"

password="dabatase's password"

扫描二维码关注公众号,回复: 1220507 查看本文章

driverClassName="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost:3306/test"

/>

1) name : 是指连接的名称。

2) auth :  是指连接池的管理权限 Container是指容器管理。

3) type : 是指对象的类型。

4) maxActive : 是指连接池中连接数据库的最大数,当设为0时则表示没有限制。

5) maxIdle : 是指等待连接的最大数量,当设为0时则表示没有限制。

6) maxWait : 是指最大的等待秒数,当设为-1时表示无线等待。

在代码中通过上下文对象引用连接池:

Conext context = new InitialConext();

DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mysql");

Connection conn = ds.getConnection();

之后该怎么进行就随意了。

其中高亮的部分为连接池的名称。

猜你喜欢

转载自moonglade.iteye.com/blog/1408122