学用数据库连接池后记录一下,网上搜集资料->测试成功->记下方法(忘了是从哪儿看到了这个方法):
1. 创建proxool.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>oracle</alias>
<driver-url>jdbc:oracle:thin:@192.168.0.221:1521:XXX</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value="user" />
<property name="password" value="123456" />
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>
select * from SYSTEM.HELP where rownum=1
</house-keeping-test-sql>
</proxool>
</something-else-entirely>
2. 在web.xml中配置
<!-- database connection pool(proxool) config -->
<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/config/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- database connection pool(proxool) admin config -->
<servlet>
<servlet-name>proxoolAdmin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>proxoolAdmin</servlet-name>
<url-pattern>/proxool</url-pattern>
</servlet-mapping>
3.使用(connection使用完毕之后一定要关闭,不然会每次都新建一个数据库连接).
/**
* 获取数据库连接
* @return Connection连接
* @throws Exception
*/
public static Connection getConnection() throws Exception
{
try {
// Class.forName(driver);
// return DriverManager.getConnection(url, userName, password);
return DriverManager.getConnection("proxool.oracle"); // 使用数据库连接池取得数据库连接
} catch (SQLException sqle) {
log.error("连接数据库时出现异常!抛出异常地点:(" + DataSource.class + ")");
throw new Exception("连接数据库时出现异常!抛出异常地点:(" + DataSource.class + ")",sqle);
}
}
4. proxool状态查看页面 http://localhost:8080/yourApp/proxool
1. 创建proxool.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>oracle</alias>
<driver-url>jdbc:oracle:thin:@192.168.0.221:1521:XXX</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties>
<property name="user" value="user" />
<property name="password" value="123456" />
</driver-properties>
<maximum-connection-count>10</maximum-connection-count>
<house-keeping-test-sql>
select * from SYSTEM.HELP where rownum=1
</house-keeping-test-sql>
</proxool>
</something-else-entirely>
2. 在web.xml中配置
<!-- database connection pool(proxool) config -->
<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/config/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- database connection pool(proxool) admin config -->
<servlet>
<servlet-name>proxoolAdmin</servlet-name>
<servlet-class>
org.logicalcobwebs.proxool.admin.servlet.AdminServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>proxoolAdmin</servlet-name>
<url-pattern>/proxool</url-pattern>
</servlet-mapping>
3.使用(connection使用完毕之后一定要关闭,不然会每次都新建一个数据库连接).
/**
* 获取数据库连接
* @return Connection连接
* @throws Exception
*/
public static Connection getConnection() throws Exception
{
try {
// Class.forName(driver);
// return DriverManager.getConnection(url, userName, password);
return DriverManager.getConnection("proxool.oracle"); // 使用数据库连接池取得数据库连接
} catch (SQLException sqle) {
log.error("连接数据库时出现异常!抛出异常地点:(" + DataSource.class + ")");
throw new Exception("连接数据库时出现异常!抛出异常地点:(" + DataSource.class + ")",sqle);
}
}
4. proxool状态查看页面 http://localhost:8080/yourApp/proxool