Proxool连接池 配置

xiaoxiao2021-03-01  32

首先要将配置Proxool需要jar包放入项目中 web根目录下lib里面 commons-logging.jar、proxool-0.9.1.jar、proxool-cglib.jar

然后开始配置

首先在WEB-INF下新建一个proxool.xml文件,并配置关键代码如下:

<something-else-entirely> <proxool> <alias>Jeelon</alias> <driver-url>jdbc:sqlserver://localhost:1433;databaseName=JeelonBookShopping</driver-url> <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class> <driver-properties> <property name="user" value="sa" /> <property name="password" value="630923" /> </driver-properties> <house-keeping-sleep-time>90000</house-keeping-sleep-time> <maximum-new-connections>20</maximum-new-connections> <prototype-count>5</prototype-count> <maximum-connection-count>1000</maximum-connection-count> <minimum-connection-count>10</minimum-connection-count> </proxool> </something-else-entirely>

然后开始配置web.xml文件 其关键代码如下:

<servlet> <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> <servlet> <servlet-name>Admin</servlet-name> <servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Admin</servlet-name> <url-pattern>/admin</url-pattern> </servlet-mapping> <!-- 配置受保护域,只有Tomcat管理员才能察看连接池的信息 --> <security-constraint> <web-resource-collection> <web-resource-name>proxool</web-resource-name> <url-pattern>/admin</url-pattern> </web-resource-collection> <auth-constraint> <role-name>manager</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>proxool manager Application</realm-name> </login-config> <security-role> <description>The role that is required to log in to the Manager Application</description> <role-name>manager</role-name> </security-role> <error-page> <error-code>401</error-code> <location>/401.jsp</location> </error-page>

做完以上两步骤之后 接下来 java代码获得连接 代码如下:

package com.jeelon.dbconnection; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBProXool { private static Connection connection = null ; private DBProXool(){ } public static Connection getConnection(){ try { connection = DriverManager.getConnection("proxool.Jeelon"); } catch (SQLException e) { e.printStackTrace(); } return connection; } }

通过测试 Proxool就配置好啦 以上是针对SQLServer 2005 的配置 其他数据同理 只需要改变url和驱动就OK啦 ...

...

转载请注明原文地址: https://www.6miu.com/read-3650034.html

最新回复(0)