配置Proxool连接池的几种方式
 
 
1. 获取连接时向驱动传递一个 java.util.Properties :
Properties info = new Properties();
info.setProperty("proxool.maximum-connection-count", "20");
info.setProperty("proxool.house-keeping-test-sql", "select CURRENT_DATE");
info.setProperty("user", "sa");
info.setProperty("password", "");
String alias = "test";
String driverClass = "org.hsqldb.jdbcDriver";
String driverUrl = "jdbc:hsqldb:test";
String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl;
connection = DriverManager.getConnection(url, info);
 
 
 
2. 使用XML文件 :
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- the proxool configuration can be embedded within your own application's.
Anything outside the "proxool" tag is ignored. -->
<something-else-entirely>
  <proxool>
    <alias>xml-test</alias>
    <driver-url>jdbc:hsqldb:.</driver-url>
    <driver-class>org.hsqldb.jdbcDriver</driver-class>
    <driver-properties>
      <property name="user" value="sa"/>
      <property name="password" value=""/>
    </driver-properties>
    <maximum-connection-count>10</maximum-connection-count>
    <house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
  </proxool>
</something-else-entirely>
 
然后在你的启动代码中简单地调用 XML configurator (JAXPConfigurator) :
 
JAXPConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test-no-ns.xml", false);
// The false means non-validating
 
之后,获取连接是非常简单的("xml-test"是我们在上面配置文件中使用的别名)
connection = DriverManager.getConnection("proxool.xml-test");
 
注意: 你需要一个 JAXP 兼容的 XML 解析器来使用这种配置方式。例如 Crimson 或者 Xerces 。
 
3. 使用一个文本属性文件 :
jdbc-0.proxool.alias=property-test
jdbc-0.proxool.driver-url=jdbc:hsqldb:.
jdbc-0.proxool.driver-class=org.hsqldb.jdbcDriver
jdbc-0.user=sa
jdbc-0.password=
jdbc-0.proxool.maximum-connection-count=10
jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
 
第一个词必须以"jdbc"开头。每一个池使用惟一的名称。任何没有以"jdbc"开头的属性将被忽略。每个属性要有前缀"proxool."。
然后在你的启动代码中简单地调用属性配置器(PropertyConfigurator):
 
PropertyConfigurator.configure("src/java-test/org/logicalcobwebs/proxool/configuration/test.properties");
 
获取连接是非常简单的。("property-test"是在上面定义的别名)
connection = DriverManager.getConnection("proxool.property-test");
 
 
 
4. 程序中加载 :
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Properties info = new Properties();
info.setProperty("proxool.maximum-connection-count", "10");
info.setProperty("proxool.house-keeping-test-sql", "select CURRENT_DATE");
info.setProperty("user", "sa");
info.setProperty("password", "");
String alias = "test";
String driverClass = "org.hsqldb.jdbcDriver";
String driverUrl = "jdbc:hsqldb:test";
String url = "proxool." + alias + ":" + driverClass + ":" + driverUrl;
ProxoolFacade.registerConnectionPool(url, info);
 
获取连接是非常简单的。("test"是在上面定义的别名)
connection = DriverManager.getConnection("proxool.test");
 
 
 
5. 使用Avalon (如果你的项目中使用了Avalon就是用这种方式:
 
role.config -
<role-list>
  <role
    name="org.logicalcobwebs.proxool.configuration.AvalonConfigurator"
    shorthand="proxool-config"
    default-class="org.logicalcobwebs.proxool.configuration.AvalonConfigurator"/>
</role-list>
 
component.config -
<component-config>
  <proxool-config>
    <proxool>
      <alias>avalon-test</alias>
      <driver-url>jdbc:hsqldb:.</driver-url>
      <driver-class>org.hsqldb.jdbcDriver</driver-class>
      <driver-properties>
        <property name="user" value="sa"/>
        <property name="password" value=""/>
      </driver-properties>
    </proxool>
  </proxool-config>
</component-config>