配置之前必须引入proxool-0.9.0RC1.jar包。
配置 一:xml方法
首先在WEB-INF目录下创建proxool.xml文件,内容如下:
<!-- the proxool configuration can be embedded within your own application's.
???? Anything outside the "proxool" tag is ignored. -->
????
<something-else-entirely>
????<proxool>
????????<alias>mydata</alias>
????????<driver-url>
???????????? jdbc:jtds:sqlserver://localhost:1433;DatabaseName=mydatabase
????????</driver-url>
????????<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
????????<driver-properties>
????????????<property name="user" value="sa" />
????????????<property name="password" value="sa" />
????????</driver-properties>
????????<maximum-connection-count>20</maximum-connection-count>
????????<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
????</proxool>
</something-else-entirely>
alias是别名;
driver-url是驱动的url,就是连接的url;
driver-class是驱动的类,就是数据库驱动;
driver-properties是驱动的属性,可以设置登陆数据库的用户名和密码。
maximum-connection-count是最大连接数。
在工程的web.xml里添加如下内容:
????<servlet-name>ServletConfigurator</servlet-name>
????<servlet-class>
????????? org.logicalcobwebs.proxool.configuration.ServletConfigurator
????</servlet-class>
????<init-param>
????????? param-name>xmlFile</param-name>
????<param-value>WEB-INF/proxool.xml</param-value>
????</init-param>
????<load-on-startup>1</load-on-startup>
</servlet>
这段标记是要求tomcat在启动的时候加载proxool驱动并且指明 proxool.xml的位置。
配置二:property方法
首先在WEB-INF目录下创建proxool.properties文件,内容如下:
jdbc-0.proxool.alias=mydata??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? jdbc-0.proxool.driver-class=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc-0.proxool.driver-url=jdbc:microsoft:sqlserver://localhost:1433;databaseName=mydatabase??????????????????? jdbc-0.user=sa????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? jdbc-0.password=sa?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? jdbc-0.proxool.maximum-connection-count=20
jdbc-0.proxool.prototype-count=4
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
jdbc-0.proxool.verbose=true
jdbc-0.proxool.statistics=10s,1m,1d
jdbc-0.proxool.statistics-log-level=DEBUG
在工程的web.xml里添加如下内容:
????<servlet-name>ServletConfigurator</servlet-name>
????<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
????<init-param>
??????<param-name>propertyFile</param-name>
??????<param-value>WEB-INF/proxool.properties</param-value>
????</init-param>
????<load-on-startup>1</load-on-startup>
??</servlet>
到此proxool的配置就完成了,建立链接时需要如下代码:
?? Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
??? Connection conn = DriverManager.getConnection("proxool.mydata");??? //mydata为alias中的别名
其它配置属性:
maximum-connection-lifetime?? 最大连接生命周期 默认值:4小时
maximum-active-time:????? 最大活动时间??? 默认值:5分钟
maximum-connection-count??? 最大连接数???? 默认值:15个
minimum-connection-count??? 最小连接数???? 默认值:5个
?