- 浏览: 1633169 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (288)
- XML (4)
- Eclipse运用 (22)
- Exception (10)
- Spring (24)
- ActiveMQ (2)
- Java Message Service (1)
- Maven (27)
- Git (14)
- Java IO (1)
- 驾校考试 (1)
- 正则表达式 (1)
- Tomcat (9)
- JQuery (32)
- JavaScript (4)
- 数据库 (8)
- Linux (17)
- Mybatis/IBatis (2)
- Java 网络编程 (2)
- Java (43)
- WebService (1)
- VMware (2)
- Java日志 (4)
- Velocity (1)
- Node JS (3)
- Interview (21)
- Http (3)
- JAXB (4)
- JSON (5)
- Java Thread (7)
- Hibernate (4)
- JDK (0)
- Schedule (3)
- Html, (1)
- 设计模式 (5)
- CI (1)
- Android (4)
- Solr (16)
- UML (9)
- esper (7)
- kafka (2)
- DFS (6)
- redis (6)
- Shiro (1)
- SPDY (1)
- 算法 (4)
- snmp (1)
- Servlet (0)
- 数据库,连接池 (2)
- 性能调试 (4)
- 编码 (2)
- Jetty (1)
- windows (1)
- jersey (0)
- 协议 (4)
- MQTT (2)
- idea (2)
- C++ (2)
- Interview,Python (1)
- 通信相关 (1)
最新评论
-
di1984HIT:
Java如何获取VMware中Vcenter/ServerInstance下的各种硬件信息 -
yhxf_ie:
赞!!
详解Git工作区、暂存区、历史记录区以及git reset、git revert、git checkout等撤销命令的区别 -
sj5455718:
...
Java时区处理之夏令时,冬令时 - 美国的6个时区 -
路小尘:
暴露了你的东家,swang6@ebay.com, 哈哈。我没找 ...
Tomcat启动完成后再执行一个指定的方法 - 不影响Tomcat的启动时间 -
一路丿向北:
VCenter、ESXServer、Cluster这些实体类在 ...
Java如何获取VMware中Vcenter/ServerInstance下的各种硬件信息
<div class="iteye-blog-content-contain" style="font-size: 14px;">
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">一、概述:</span></strong></p>
<p><span style=""> 数据库连接池C3P0框架是个非常优异的开源jar,高性能的管理着数据源,c3p0有两种数据源管理方式,一种是通过程序变本身来进行管理,还有一种是通过容器管理,本节讨论通过程序本身来进行管理,下一节讨论通过容器进行管理。</span></p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">二、c3p0的三种实现方式</span></strong></p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1、实现方式一:利用c3p0的API自己动手</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">写代码,实现数据源</span></strong></p>
<p><span style="">例如:在类路径下配置一个属性文件,config.properties,内容如下:</span></p>
<p> </p>
<pre name="code" class="java">driverClass=xxx
jdbcUrl=xxx
user=xxx
password=xxx</pre>
<p> </p>
<p> </p>
<p><span style="">相关的Java程序片段为:</span></p>
<p> </p>
<pre name="code" class="java">Properties props = new Properties();
InputStream in = Thread.class.getResourceAsStream("config.properties");
props.load(in);
in.close();
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass(props.getProperty("driverClass"));
cpds.setJdbcUrl(props.getProperty("jdbcUrl"));
cpds.setUser(props.getProperty("user"));
cpds.setPassword(props.getProperty("password"));</pre>
<p> 这里只实现了一个数据源,也可以在类路径下配置一个xml文件,config.xml</p>
<p> </p>
<p> </p>
<pre name="code" class="xml"><config>
<source name="source1">
<property name="user">root</property>
<property name="password">xxx</property>
<property name="url">xxx</property>
<property name="driverClass">xxx</property>
</source>
<source name="source2">
...
</source>
</config></pre>
<p> <span style="">然后自己解析xml文件,这样可以实现多个数据源的配置</span></p>
<p> </p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2、实现方式二:</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">类路径下提供一个c3p0.properties文件,文件名必须为c3p0.properties</span></strong></p>
<p><span style="">配置如下:</span></p>
<p> </p>
<pre name="code" class="xml">#驱动
c3p0.driverClass=com.mysql.jdbc.Driver
#地址
c3p0.jdbcUrl=jdbc:mysql://d-shc-00426378/tools
#用户名
c3p0.user=root
#密码
c3p0.password=root</pre>
<p> <span style="">这里只提供了最基本的配置项,其他配置项参照 </span><a style="" href="http://www.mchange.com/projects/c3p0/index.html#c3p0-config.xml" target="_blank">文档</a><span style="">配置,记得是c3p0.后面加属性名就是了,最后初始化数据源的方式就是这样简单:</span></p>
<p> </p>
<p> </p>
<pre name="code" class="java">...
DataSource ds = new ComboPooledDataSource();
return ds;
...</pre>
<p> <span style="">然后就可以使用数据源了,C3P0会对c3p0.properties进行自动解析的。</span></p>
<p> </p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3、实现方式二:</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">类</span></strong><span style=""><strong>路径下提供一个c3p0-config.xml文件</strong> <br></span></p>
<p><span style="">这种方式与第二种差不多,但是有更多的优点 </span><br style=""><span style="">(1).更直观明显,很类似hibernate和spring的配置</span><br style=""><span style="">(2).可以为多个数据源服务,提供default-config和named-config两种配置方式 <br></span></p>
<p> </p>
<pre name="code" class="xml"><c3p0-config>
<default-config>
<property name="user">root</property>
<property name="password">java</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">100</property>
<property name="minPoolSize">10</property>
</default-config>
<named-config name="mySource">
<property name="user">root</property>
<property name="password">java</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">100</property>
<property name="minPoolSize">10</property>
</named-config>
</c3p0-config></pre>
<p> </p>
<pre name="code" class="java">...
DataSource ds = new ComboPooledDataSource("mySource");
return ds;
...</pre>
<p> <span style=""><span style="">这样就可以使用数据源了。</span></span></p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">三、实例,以第二种方式,即c3p0.propertis的方式为例说明</span></span></strong></p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1、在classpath下创建一个文件,c3p0.properteis</span></span></strong></p>
<p> </p>
<pre name="code" class="xml">#驱动
c3p0.driverClass=com.mysql.jdbc.Driver
#地址
c3p0.jdbcUrl=jdbc:mysql://d-shc-00426378/tools
#用户名
c3p0.user=root
#密码
c3p0.password=root
#-------------------------------
#连接池初始化时创建的连接数
c3p0.initialPoolSize=3
#连接池保持的最小连接数
c3p0.minPoolSize=3
#连接池在无空闲连接可用时一次性创建的新数据库连接数,default:3
c3p0.acquireIncrement=3
#连接池中拥有的最大连接数,如果获得新连接时会使连接总数超过这个值则不会再获取新连接,而是等待其他连接释放,所以这个值有可能会设计地很大,default : 15
c3p0.maxPoolSize=15
#连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接,单位秒
c3p0.maxIdleTime=100
#连接池在获得新连接失败时重试的次数,如果小于等于0则无限重试直至连接获得成功
c3p0.acquireRetryAttempts=30
#连接池在获得新连接时的间隔时间
c3p0.acquireRetryDelay=1000</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2、封装一个C3p0ConnectionPool用来创建数据库连接</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0ConnectionPool {
private DataSource ds;
private static C3p0ConnectionPool pool;
private C3p0ConnectionPool() {
ds = new ComboPooledDataSource();
}
// 加上synchronized就是典型的同步模式
public static /*synchronized*/ final C3p0ConnectionPool getInstance() {
if (pool == null) {
try {
pool = new C3p0ConnectionPool();
} catch (Exception e) {
e.printStackTrace();
}
}
return pool;
}
// synchronized保证每个pool线程请求返回的都是不同的Connection
public synchronized final Connection getConnection() {
try {
Connection connection = ds.getConnection();
// 1)将配置文件中的c3p0.initialPoolSize,c3p0.minPoolSize,c3p0.maxPoolSize都改为1,然后执行查看结果
// 2)将配置文件中的c3p0.initialPoolSize,c3p0.minPoolSize,c3p0.maxPoolSize都改为较小的值,加大线程数,然后执行查看结果
System.out.println(" **** current connection number: " + ((ComboPooledDataSource)ds).getNumConnections()
+ " busy connection number: " + ((ComboPooledDataSource)ds).getNumBusyConnections()
+ " Idle connection nmuber: " + ((ComboPooledDataSource)ds).getNumIdleConnections());
return connection;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3、创建模拟用户发起数据库连接的Thread类</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0PoolThread extends Thread {
@Override
public void run() {
C3p0ConnectionPool pool = C3p0ConnectionPool.getInstance();
Connection connection = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
connection = pool.getConnection();
stmt = connection.prepareStatement("select sysdate() as nowtime from dual");
rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(Thread.currentThread().getId() + "---------------开始" + rs.getString("nowtime"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getId() + "--------结束");
}
}
</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">4、Main类</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0Main {
public static void main(String[] args) {
System.out.println("数据库连接池模拟开始");
C3p0PoolThread[] threads = new C3p0PoolThread[100];
for (int i = 0; i < threads.length;i++) {
threads[i] = new C3p0PoolThread();
}
for (int i= 0;i < threads.length; i++) {
threads[i].start();
}
}
}
</pre>
<p><strong> 在C3p0Main.java中可以增加线程数,也可以再c3p0.properties中减少c3p0.maxPoolSize, c3p0.minPoolSize, c3p0.initialPoolSize等的值来查看执行结果。</strong></p>
<p> </p>
<p><strong>四、常用配置参数的说明:</strong></p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1.最常用配置</span></strong></p>
<p> </p>
<p style=""><strong>initialPoolSize:</strong> 连接池初始化时创建的连接数,default : 3(建议使用)</p>
<p style=""><strong>minPoolSize: </strong>连接池保持的最小连接数,default : 3(建议使用)</p>
<p style=""><strong>maxPoolSize: </strong>连接池中拥有的最大连接数,如果获得新连接时会使连接总数超过这个值则不会再获取新连接,而是等待其他连接释放,所以这个值有可能会设计地很大,default : 15(建议使用)</p>
<p style=""><strong>acquireIncrement:</strong>连接池在无空闲连接可用时一次性创建的新数据库连接数,default : 3(建议使用)</p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2.管理连接池的大小和连接的生存时间</span></strong></p>
<p> </p>
<p style=""><strong>maxConnectionAge</strong>:配置连接的生存时间,超过这个时间的连接将由连接池自动断开丢弃掉。当然正在使用的连接不会马上断开,而是等待它close再断开。配置为0的时候则不会对连接的生存时间进行限制。default : 0 单位 s(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxIdleTime:</strong>连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接。如果为0,则永远不会断开连接,即回收此连接。default : 0 单位 s(建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxIdleTimeExcessConnections:</strong>这个配置主要是为了快速减轻连接池的负载,比如连接池中连接数因为某次数据访问高峰导致创建了很多数据连接,但是后面的时间段需要的数据库连接数很少,需要快速释放,必须小于maxIdleTime。其实这个没必要配置,maxIdleTime已经配置了。default : 0 单位 s(不建议使用)</p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3.配置连接测试:</span></strong></p>
<p> </p>
<p style=""><strong>automaticTestTable:</strong>配置一个表名,连接池根据这个表名用自己的测试sql语句在这个空表上测试数据库连接,这个表只能由c3p0来使用,用户不能操作。default : null(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>preferredTestQuery:</strong>与上面的automaticTestTable二者只能选一。自己实现一条SQL检测语句。default : null(建议使用)</p>
<p style=""> </p>
<p style=""><strong>idleConnectionTestPeriod:</strong>用来配置测试空闲连接的间隔时间。测试方式还是上面的两种之一,可以用来解决MySQL8小时断开连接的问题。因为它保证连接池会每隔一定时间对空闲连接进行一次测试,从而保证有效的空闲连接能每隔一定时间访问一次数据库,将于MySQL8小时无会话的状态打破。为0则不测试。default : 0(建议使用)</p>
<p style=""> </p>
<p style=""><strong>testConnectionOnCheckin:</strong>如果为true,则在close的时候测试连接的有效性。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>testConnectionOnCheckout:</strong>性能消耗大。如果为true,在每次getConnection的时候都会测试,为了提高性能,尽量不要用。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>4.配置PreparedStatement缓存:</strong></p>
<p style=""><strong>maxStatements:</strong>连接池为数据源缓存的PreparedStatement的总数。由于PreparedStatement属于单个Connection,所以这个数量应该根据应用中平均连接数乘以每个连接的平均PreparedStatement来计算。同时maxStatementsPerConnection的配置无效。default : 0(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxStatementsPerConnection:</strong>连接池为数据源单个Connection缓存的PreparedStatement数,这个配置比maxStatements更有意义,因为它缓存的服务对象是单个数据连接,如果设置的好,肯定是可以提高性能的。为0的时候不缓存。default : 0(看情况而论)</p>
<p style=""> </p>
<p style=""><strong>5.重连相关配置 </strong></p>
<p style=""><strong>acquireRetryAttempts:</strong>连接池在获得新连接失败时重试的次数,如果小于等于0则无限重试直至连接获得成功。default : 30(建议使用)</p>
<p style=""> </p>
<p style=""><strong>acquireRetryDelay:</strong>连接池在获得新连接时的间隔时间。default : 1000 单位ms(建议使用)</p>
<p style=""> </p>
<p style=""><strong>breakAfterAcquireFailure:</strong>如果为true,则当连接获取失败时自动关闭数据源,除非重新启动应用程序。所以一般不用。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>checkoutTimeout:</strong>配置当连接池所有连接用完时应用程序getConnection的等待时间。为0则无限等待直至有其他连接释放或者创建新的连接,不为0则当时间到的时候如果仍没有获得连接,则会抛出SQLException。其实就是acquireRetryAttempts*acquireRetryDelay。default : 0(与上面两个,有重复,选择其中两个都行)</p>
<p style=""> </p>
<p style=""><strong>6.定制管理Connection的生命周期</strong></p>
<p style=""><strong>connectionCustomizerClassName:</strong>用来定制Connection的管理,比如在Connection acquire 的时候设定Connection的隔离级别,或者在Connection丢弃的时候进行资源关闭,</p>
<p style="">就可以通过继承一个AbstractConnectionCustomizer来实现相关方法,配置的时候使用全类名。有点类似监听器的作用。default : null(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>7.配置未提交的事务处理 </strong></p>
<p style=""><strong>autoCommitOnClose:</strong>连接池在回收数据库连接时是否自动提交事务。如果为false,则会回滚未提交的事务,如果为true,则会自动提交事务。default : false(不建议使用)</p>
<p style=""><strong>forceIgnoreUnresolvedTransactions:</strong>这个配置强烈不建议为true。default : false(不建议使用)</p>
<p style="">一般来说事务当然由自己关闭了,为什么要让连接池来处理这种不细心问题呢?</p>
<p style=""> </p>
<p style=""><strong>8.配置debug和回收Connection</strong></p>
<p style=""><strong>unreturnedConnectionTimeout:</strong>为0的时候要求所有的Connection在应用程序中必须关闭。如果不为0,则强制在设定的时间到达后回收Connection,所以必须小心设置,保证在回收之前所有数据库操作都能够完成。这种限制减少Connection未关闭情况的不是很适用。建议手动关闭。default : 0 单位 s(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>debugUnreturnedConnectionStackTraces:</strong>如果为true并且unreturnedConnectionTimeout设为大于0的值,当所有被getConnection出去的连接unreturnedConnectionTimeout时间到的时候,就会打印出堆栈信息。只能在debug模式下适用,因为打印堆栈信息会减慢getConnection的速度default : false(不建议使用)</p>
<p style=""> </p>
<p style="">其他配置项:因为有些配置项几乎没有自己配置的必要,使用默认值就好,所以没有再写出来。</p>
<p> </p>
</div>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">一、概述:</span></strong></p>
<p><span style=""> 数据库连接池C3P0框架是个非常优异的开源jar,高性能的管理着数据源,c3p0有两种数据源管理方式,一种是通过程序变本身来进行管理,还有一种是通过容器管理,本节讨论通过程序本身来进行管理,下一节讨论通过容器进行管理。</span></p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">二、c3p0的三种实现方式</span></strong></p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1、实现方式一:利用c3p0的API自己动手</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">写代码,实现数据源</span></strong></p>
<p><span style="">例如:在类路径下配置一个属性文件,config.properties,内容如下:</span></p>
<p> </p>
<pre name="code" class="java">driverClass=xxx
jdbcUrl=xxx
user=xxx
password=xxx</pre>
<p> </p>
<p> </p>
<p><span style="">相关的Java程序片段为:</span></p>
<p> </p>
<pre name="code" class="java">Properties props = new Properties();
InputStream in = Thread.class.getResourceAsStream("config.properties");
props.load(in);
in.close();
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass(props.getProperty("driverClass"));
cpds.setJdbcUrl(props.getProperty("jdbcUrl"));
cpds.setUser(props.getProperty("user"));
cpds.setPassword(props.getProperty("password"));</pre>
<p> 这里只实现了一个数据源,也可以在类路径下配置一个xml文件,config.xml</p>
<p> </p>
<p> </p>
<pre name="code" class="xml"><config>
<source name="source1">
<property name="user">root</property>
<property name="password">xxx</property>
<property name="url">xxx</property>
<property name="driverClass">xxx</property>
</source>
<source name="source2">
...
</source>
</config></pre>
<p> <span style="">然后自己解析xml文件,这样可以实现多个数据源的配置</span></p>
<p> </p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2、实现方式二:</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">类路径下提供一个c3p0.properties文件,文件名必须为c3p0.properties</span></strong></p>
<p><span style="">配置如下:</span></p>
<p> </p>
<pre name="code" class="xml">#驱动
c3p0.driverClass=com.mysql.jdbc.Driver
#地址
c3p0.jdbcUrl=jdbc:mysql://d-shc-00426378/tools
#用户名
c3p0.user=root
#密码
c3p0.password=root</pre>
<p> <span style="">这里只提供了最基本的配置项,其他配置项参照 </span><a style="" href="http://www.mchange.com/projects/c3p0/index.html#c3p0-config.xml" target="_blank">文档</a><span style="">配置,记得是c3p0.后面加属性名就是了,最后初始化数据源的方式就是这样简单:</span></p>
<p> </p>
<p> </p>
<pre name="code" class="java">...
DataSource ds = new ComboPooledDataSource();
return ds;
...</pre>
<p> <span style="">然后就可以使用数据源了,C3P0会对c3p0.properties进行自动解析的。</span></p>
<p> </p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3、实现方式二:</span><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">类</span></strong><span style=""><strong>路径下提供一个c3p0-config.xml文件</strong> <br></span></p>
<p><span style="">这种方式与第二种差不多,但是有更多的优点 </span><br style=""><span style="">(1).更直观明显,很类似hibernate和spring的配置</span><br style=""><span style="">(2).可以为多个数据源服务,提供default-config和named-config两种配置方式 <br></span></p>
<p> </p>
<pre name="code" class="xml"><c3p0-config>
<default-config>
<property name="user">root</property>
<property name="password">java</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">100</property>
<property name="minPoolSize">10</property>
</default-config>
<named-config name="mySource">
<property name="user">root</property>
<property name="password">java</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/jdbc</property>
<property name="initialPoolSize">10</property>
<property name="maxIdleTime">30</property>
<property name="maxPoolSize">100</property>
<property name="minPoolSize">10</property>
</named-config>
</c3p0-config></pre>
<p> </p>
<pre name="code" class="java">...
DataSource ds = new ComboPooledDataSource("mySource");
return ds;
...</pre>
<p> <span style=""><span style="">这样就可以使用数据源了。</span></span></p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">三、实例,以第二种方式,即c3p0.propertis的方式为例说明</span></span></strong></p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1、在classpath下创建一个文件,c3p0.properteis</span></span></strong></p>
<p> </p>
<pre name="code" class="xml">#驱动
c3p0.driverClass=com.mysql.jdbc.Driver
#地址
c3p0.jdbcUrl=jdbc:mysql://d-shc-00426378/tools
#用户名
c3p0.user=root
#密码
c3p0.password=root
#-------------------------------
#连接池初始化时创建的连接数
c3p0.initialPoolSize=3
#连接池保持的最小连接数
c3p0.minPoolSize=3
#连接池在无空闲连接可用时一次性创建的新数据库连接数,default:3
c3p0.acquireIncrement=3
#连接池中拥有的最大连接数,如果获得新连接时会使连接总数超过这个值则不会再获取新连接,而是等待其他连接释放,所以这个值有可能会设计地很大,default : 15
c3p0.maxPoolSize=15
#连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接,单位秒
c3p0.maxIdleTime=100
#连接池在获得新连接失败时重试的次数,如果小于等于0则无限重试直至连接获得成功
c3p0.acquireRetryAttempts=30
#连接池在获得新连接时的间隔时间
c3p0.acquireRetryDelay=1000</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2、封装一个C3p0ConnectionPool用来创建数据库连接</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0ConnectionPool {
private DataSource ds;
private static C3p0ConnectionPool pool;
private C3p0ConnectionPool() {
ds = new ComboPooledDataSource();
}
// 加上synchronized就是典型的同步模式
public static /*synchronized*/ final C3p0ConnectionPool getInstance() {
if (pool == null) {
try {
pool = new C3p0ConnectionPool();
} catch (Exception e) {
e.printStackTrace();
}
}
return pool;
}
// synchronized保证每个pool线程请求返回的都是不同的Connection
public synchronized final Connection getConnection() {
try {
Connection connection = ds.getConnection();
// 1)将配置文件中的c3p0.initialPoolSize,c3p0.minPoolSize,c3p0.maxPoolSize都改为1,然后执行查看结果
// 2)将配置文件中的c3p0.initialPoolSize,c3p0.minPoolSize,c3p0.maxPoolSize都改为较小的值,加大线程数,然后执行查看结果
System.out.println(" **** current connection number: " + ((ComboPooledDataSource)ds).getNumConnections()
+ " busy connection number: " + ((ComboPooledDataSource)ds).getNumBusyConnections()
+ " Idle connection nmuber: " + ((ComboPooledDataSource)ds).getNumIdleConnections());
return connection;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3、创建模拟用户发起数据库连接的Thread类</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0PoolThread extends Thread {
@Override
public void run() {
C3p0ConnectionPool pool = C3p0ConnectionPool.getInstance();
Connection connection = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
connection = pool.getConnection();
stmt = connection.prepareStatement("select sysdate() as nowtime from dual");
rs = stmt.executeQuery();
while (rs.next()) {
System.out.println(Thread.currentThread().getId() + "---------------开始" + rs.getString("nowtime"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
rs.close();
stmt.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(Thread.currentThread().getId() + "--------结束");
}
}
</pre>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;"><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">4、Main类</span></span></strong></p>
<p> </p>
<pre name="code" class="java">package com.wsheng.aggregator.c3p0;
/**
* @author Josh Wang(Sheng)
*
* @email josh_wang23@hotmail.com
*
*/
public class C3p0Main {
public static void main(String[] args) {
System.out.println("数据库连接池模拟开始");
C3p0PoolThread[] threads = new C3p0PoolThread[100];
for (int i = 0; i < threads.length;i++) {
threads[i] = new C3p0PoolThread();
}
for (int i= 0;i < threads.length; i++) {
threads[i].start();
}
}
}
</pre>
<p><strong> 在C3p0Main.java中可以增加线程数,也可以再c3p0.properties中减少c3p0.maxPoolSize, c3p0.minPoolSize, c3p0.initialPoolSize等的值来查看执行结果。</strong></p>
<p> </p>
<p><strong>四、常用配置参数的说明:</strong></p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">1.最常用配置</span></strong></p>
<p> </p>
<p style=""><strong>initialPoolSize:</strong> 连接池初始化时创建的连接数,default : 3(建议使用)</p>
<p style=""><strong>minPoolSize: </strong>连接池保持的最小连接数,default : 3(建议使用)</p>
<p style=""><strong>maxPoolSize: </strong>连接池中拥有的最大连接数,如果获得新连接时会使连接总数超过这个值则不会再获取新连接,而是等待其他连接释放,所以这个值有可能会设计地很大,default : 15(建议使用)</p>
<p style=""><strong>acquireIncrement:</strong>连接池在无空闲连接可用时一次性创建的新数据库连接数,default : 3(建议使用)</p>
<p> </p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">2.管理连接池的大小和连接的生存时间</span></strong></p>
<p> </p>
<p style=""><strong>maxConnectionAge</strong>:配置连接的生存时间,超过这个时间的连接将由连接池自动断开丢弃掉。当然正在使用的连接不会马上断开,而是等待它close再断开。配置为0的时候则不会对连接的生存时间进行限制。default : 0 单位 s(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxIdleTime:</strong>连接的最大空闲时间,如果超过这个时间,某个数据库连接还没有被使用,则会断开掉这个连接。如果为0,则永远不会断开连接,即回收此连接。default : 0 单位 s(建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxIdleTimeExcessConnections:</strong>这个配置主要是为了快速减轻连接池的负载,比如连接池中连接数因为某次数据访问高峰导致创建了很多数据连接,但是后面的时间段需要的数据库连接数很少,需要快速释放,必须小于maxIdleTime。其实这个没必要配置,maxIdleTime已经配置了。default : 0 单位 s(不建议使用)</p>
<p> </p>
<p><strong><span style="color: #000000; font-family: Helvetica,Tahoma,Arial,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 25.2px; text-align: left; text-indent: 0px; white-space: normal; display: inline ! important; float: none; background-color: #ffffff;">3.配置连接测试:</span></strong></p>
<p> </p>
<p style=""><strong>automaticTestTable:</strong>配置一个表名,连接池根据这个表名用自己的测试sql语句在这个空表上测试数据库连接,这个表只能由c3p0来使用,用户不能操作。default : null(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>preferredTestQuery:</strong>与上面的automaticTestTable二者只能选一。自己实现一条SQL检测语句。default : null(建议使用)</p>
<p style=""> </p>
<p style=""><strong>idleConnectionTestPeriod:</strong>用来配置测试空闲连接的间隔时间。测试方式还是上面的两种之一,可以用来解决MySQL8小时断开连接的问题。因为它保证连接池会每隔一定时间对空闲连接进行一次测试,从而保证有效的空闲连接能每隔一定时间访问一次数据库,将于MySQL8小时无会话的状态打破。为0则不测试。default : 0(建议使用)</p>
<p style=""> </p>
<p style=""><strong>testConnectionOnCheckin:</strong>如果为true,则在close的时候测试连接的有效性。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>testConnectionOnCheckout:</strong>性能消耗大。如果为true,在每次getConnection的时候都会测试,为了提高性能,尽量不要用。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>4.配置PreparedStatement缓存:</strong></p>
<p style=""><strong>maxStatements:</strong>连接池为数据源缓存的PreparedStatement的总数。由于PreparedStatement属于单个Connection,所以这个数量应该根据应用中平均连接数乘以每个连接的平均PreparedStatement来计算。同时maxStatementsPerConnection的配置无效。default : 0(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>maxStatementsPerConnection:</strong>连接池为数据源单个Connection缓存的PreparedStatement数,这个配置比maxStatements更有意义,因为它缓存的服务对象是单个数据连接,如果设置的好,肯定是可以提高性能的。为0的时候不缓存。default : 0(看情况而论)</p>
<p style=""> </p>
<p style=""><strong>5.重连相关配置 </strong></p>
<p style=""><strong>acquireRetryAttempts:</strong>连接池在获得新连接失败时重试的次数,如果小于等于0则无限重试直至连接获得成功。default : 30(建议使用)</p>
<p style=""> </p>
<p style=""><strong>acquireRetryDelay:</strong>连接池在获得新连接时的间隔时间。default : 1000 单位ms(建议使用)</p>
<p style=""> </p>
<p style=""><strong>breakAfterAcquireFailure:</strong>如果为true,则当连接获取失败时自动关闭数据源,除非重新启动应用程序。所以一般不用。default : false(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>checkoutTimeout:</strong>配置当连接池所有连接用完时应用程序getConnection的等待时间。为0则无限等待直至有其他连接释放或者创建新的连接,不为0则当时间到的时候如果仍没有获得连接,则会抛出SQLException。其实就是acquireRetryAttempts*acquireRetryDelay。default : 0(与上面两个,有重复,选择其中两个都行)</p>
<p style=""> </p>
<p style=""><strong>6.定制管理Connection的生命周期</strong></p>
<p style=""><strong>connectionCustomizerClassName:</strong>用来定制Connection的管理,比如在Connection acquire 的时候设定Connection的隔离级别,或者在Connection丢弃的时候进行资源关闭,</p>
<p style="">就可以通过继承一个AbstractConnectionCustomizer来实现相关方法,配置的时候使用全类名。有点类似监听器的作用。default : null(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>7.配置未提交的事务处理 </strong></p>
<p style=""><strong>autoCommitOnClose:</strong>连接池在回收数据库连接时是否自动提交事务。如果为false,则会回滚未提交的事务,如果为true,则会自动提交事务。default : false(不建议使用)</p>
<p style=""><strong>forceIgnoreUnresolvedTransactions:</strong>这个配置强烈不建议为true。default : false(不建议使用)</p>
<p style="">一般来说事务当然由自己关闭了,为什么要让连接池来处理这种不细心问题呢?</p>
<p style=""> </p>
<p style=""><strong>8.配置debug和回收Connection</strong></p>
<p style=""><strong>unreturnedConnectionTimeout:</strong>为0的时候要求所有的Connection在应用程序中必须关闭。如果不为0,则强制在设定的时间到达后回收Connection,所以必须小心设置,保证在回收之前所有数据库操作都能够完成。这种限制减少Connection未关闭情况的不是很适用。建议手动关闭。default : 0 单位 s(不建议使用)</p>
<p style=""> </p>
<p style=""><strong>debugUnreturnedConnectionStackTraces:</strong>如果为true并且unreturnedConnectionTimeout设为大于0的值,当所有被getConnection出去的连接unreturnedConnectionTimeout时间到的时候,就会打印出堆栈信息。只能在debug模式下适用,因为打印堆栈信息会减慢getConnection的速度default : false(不建议使用)</p>
<p style=""> </p>
<p style="">其他配置项:因为有些配置项几乎没有自己配置的必要,使用默认值就好,所以没有再写出来。</p>
<p> </p>
</div>
相关推荐
java开发,数据库连接池c3p0所需jar包。
基于java的开发源码-数据库连接池 C3P0.src.zip 基于java的开发源码-数据库连接池 C3P0.src.zip 基于java的开发源码-数据库连接池 C3P0.src.zip 基于java的开发源码-数据库连接池 C3P0.src.zip 基于java的开发源码-...
包含了连接数据库连接池所需的大部分jar包
开源数据库连接池c3p0的jar包以及文档
c3p0数据库连接池jar包配置文件及依赖
数据库连接池C3P0,jar包,如果你需要数据库连接池的话,这个是你必须要下载的
C3P0数据库连接池和jar包,因为jdbc没有保持连接的能力,一旦超过一定时间没有使用(大约几百毫秒),连接就会被自动释放掉。而每次新建连接都需要140毫秒左右的时间,所以耗费时间比较多。若使用C3P0连接池来池化...
在缓冲池中先创建指定数量的数据库连接,当有连接请求时就从缓冲池中取出处于“空闲”状态的连接,并将此连接标记为“忙碌”,直到该请求进程结束后,它所使用的连接才会重新回到“空闲”状态,并等待下一次请求调用...
c3p0数据库连接池
数据库连接池 C3P0.src
无框架配置,纯java数据库连接池的配置。rar包中包含2个文件,一个是DBPool.java文件,一个是配置文件。
c3p0数据库连接池案例,java项目,例子结构清晰,适合新手学习
数据库连接池jar包,包含c3p0、druidjar包和依赖jar包,c3p0通过配置文件xml或者properties读取连接对象 druid通过properties读取连接,使用springJDBC JdbcTempalte简化sql操作
c3p0数据库连接池技术实例,包括了c3p0的jar包等,直接导入到eclipse或者myeclipse的工作空间后即可在Tomcat里运行
数据库连接池 C3P0.src.7z
数据库连接池负责分配、管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个
JAVA数据库连接池(C3P0,Druid,JNDI ,DBCP,Proxool,BoneCP) 源码包含各个数据库连接池的连接DEMO spring+mybatis+maven
基于Java的数据库连接池 C3P0.src.zip
基于java的数据库连接池 C3P0.src.zip