本例为myeclipse+tomcat7.0+sqlserver2008配置数据库连接池
具体步骤:
在<GlobalNamingResources> </GlobalNamingResources>节点中加入,
<Resource name="jdbc/DBPool" type="javax.sql.DataSource" password="aaaaaa" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" maxIdle="2" maxWait="5000" username="sa" url="jdbc:sqlserver://localhost:1433;DataBaseName=COFFEE" maxActive="4"/> |
属性说明:name,数据源名称,通常取”jdbc/XXX”的格式;
type,”javax.sql.DataSource”;
password,数据库用户密码;
driveClassName,数据库驱动;
maxIdle,最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连接将被标记为不可用,然后被释放。设为0表示无限制。
MaxActive,连接池的最大数据库连接数。设为0表示无限制。
maxWait ,最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
2、在你的web应用程序的web.xml中设置数据源参考,如下:
在<web-app></web-app>节点中加入,
<resource-ref> <description>DB Connection Pool</description> <res-ref-name>jdbc/DBPool</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> |
子节点说明: description,描述信息;
res-ref-name,参考数据源名字,同上一步的属性name;
res-type,资源类型,”javax.sql.DataSource”;
res-auth,”Container”;
res-sharing-scope,”Shareable”;