这样的我配置成功了,用的xml配置方式。我看到它的文档中有Proxool DataSource support的配置。 Self-deployed configuration In this scenario Proxool itself instantiates ProxoolDataSources and binds them to JNDI names. This is the least standard-conformant way of deploying a ProxoolDataSource. It is also the only way that is garanteed to work in any setting as long as there is a writable JNDI name available for the Proxool process when it starts up. You configure Proxool as you would when using it through the DriverManager. In addition you use the new 'jndi-name' configuration property to tell Proxool to wrap a pool in a ProxoolDataSource and bind it to JNDI. In addition any properties you prefix with 'jndi-' will be passed on the JNDI InitialContext used to bind Proxool. E.g:<proxool> <alias>jndi-test</alias> <driver-url>jdbc:hsqldb:.</driver-url> <driver-class>org.hsqldb.jdbcDriver</driver-class> <driver-class>org.hsqldb.jdbcDriver</driver-class> <driver-properties> <property name="user" value="sa"/> <property name="password" value=""/> </driver-properties> <jndi-name>/datasources/UserDB</jndi-name> <jndi-java.naming.factory.initial>com.caucho.naming.InitialContextFactoryImpl</jndi-java.naming.factory.initial> <jndi-java.naming.provider.url>localhost:1099</jndi-java.naming.provider.url> </proxool>Make sure that jndi-name is actually writable. Remember that the java:comp/env/ environment is read-only at runtime, so your ProxoolDataSources need to go somewhere else in this configuration scenario.Also remember that with this configuration option Proxool needs to be explicitly initialised, for example using the ServletConfigurator. 5. Configuration example for Tomcat Configuration method: ObjectFactory Configure a resource with ProxoolDataSource as the factory in server.xml (or the other places a context element can exist): <context> <Resource name="jdbc/mydatasource" auth="Container" type="javax.sql.DataSource" factory="org.logicalcobwebs.proxool.ProxoolDataSource" proxool.alias="hrs" user="joe" password="******" delegateProperties="foo=bar" proxool.driver-url="jdbc:oracle:thin:@127.0.0.1:1521:DB" proxool.driver-class="oracle.jdbc.driver.OracleDriver"/> </context>我照这样配置了,没有成功。
写个配置文件如:test.properties
jdbc-0.proxool.alias=property-test
jdbc-0.proxool.driver-url=jdbc:oracle:thin:@localhost:1521:chenjh
jdbc-0.proxool.driver-class=oracle.jdbc.driver.OracleDriver
jdbc-0.user=ff
jdbc-0.password=ff
jdbc-0.proxool.maximum-connection-count=10
jdbc-0.proxool.house-keeping-test-sql=select sysdate from dual代码示例:
PropertyConfigurator.configure("test.properties");
Connection conn = null;
conn = DriverManager.getConnection("proxool.property-test");
即可得到数据库连接。
Self-deployed configuration
In this scenario Proxool itself instantiates ProxoolDataSources and binds them to JNDI names. This is the least standard-conformant way of deploying a ProxoolDataSource. It is also the only way that is garanteed to work in any setting as long as there is a writable JNDI name available for the Proxool process when it starts up. You configure Proxool as you would when using it through the DriverManager. In addition you use the new 'jndi-name' configuration property to tell Proxool to wrap a pool in a ProxoolDataSource and bind it to JNDI. In addition any properties you prefix with 'jndi-' will be passed on the JNDI InitialContext used to bind Proxool. E.g:<proxool>
<alias>jndi-test</alias>
<driver-url>jdbc:hsqldb:.</driver-url>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<driver-class>org.hsqldb.jdbcDriver</driver-class>
<driver-properties>
<property name="user" value="sa"/>
<property name="password" value=""/>
</driver-properties>
<jndi-name>/datasources/UserDB</jndi-name>
<jndi-java.naming.factory.initial>com.caucho.naming.InitialContextFactoryImpl</jndi-java.naming.factory.initial>
<jndi-java.naming.provider.url>localhost:1099</jndi-java.naming.provider.url>
</proxool>Make sure that jndi-name is actually writable. Remember that the java:comp/env/ environment is read-only at runtime, so your ProxoolDataSources need to go somewhere else in this configuration scenario.Also remember that with this configuration option Proxool needs to be explicitly initialised, for example using the ServletConfigurator.
5. Configuration example for Tomcat
Configuration method: ObjectFactory Configure a resource with ProxoolDataSource as the factory in server.xml (or the other places a context element can exist):
<context>
<Resource
name="jdbc/mydatasource"
auth="Container"
type="javax.sql.DataSource"
factory="org.logicalcobwebs.proxool.ProxoolDataSource"
proxool.alias="hrs"
user="joe"
password="******"
delegateProperties="foo=bar"
proxool.driver-url="jdbc:oracle:thin:@127.0.0.1:1521:DB"
proxool.driver-class="oracle.jdbc.driver.OracleDriver"/>
</context>我照这样配置了,没有成功。
ConnectionPool-config.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<proxool>
<alias>SWOKY</alias>
<driver-url>
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xxx
</driver-url>
<driver-class>
com.microsoft.jdbc.sqlserver.SQLServerDriver
</driver-class>
<driver-properties>
<property name="user" value="sa"/>
<property name="password" value="zzit070318"/>
</driver-properties>
<maximum-connection-count>20</maximum-connection-count>
<house-keeping-test-sql>select CURRENT_DATE</house-keeping-test-sql>
</proxool>
---------------
再在web.xml里面加上
-----------------
<servlet>
<servlet-name>InitConnectionPool</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<!--配置文件的路径自己改--->
<param-value>/WEB-INF/ConnectionPool-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
-----------------
使用
java.sql.Connection conn =
java.sql.DriverManager.getConnection("proxool.SWOKY");
.........
conn = DriverManager.getConnection("proxool.youdatasourcename");