• 概述
  • 配置项说明
    • 基本配置项

      • username
      • password
      • url
      • driverClassname
      • connectionProperties
    • 事务相关配置项
    • 数据源链接数量配置项
    • 连接健康情况维护和检查
    • 缓存语句配置项
    • 连接泄露回收配置项

概述

官网: https://commons.apache.org/proper/commons-dbcp/index.html

commons-dbcp2包依赖于commons-pool2包中的代码来提供底层对象池机制。


DBCP现在有三种不同的版本来支持不同版本的JDBC。如下所示

  • DBCP 2 compiles and runs under Java 7 only (JDBC 4.1)

  • DBCP 1.4 compiles and runs under Java 6 only (JDBC 4)

  • DBCP 1.3 compiles and runs under Java 1.4-5 only (JDBC 3)

由Java 7运行的应用程序应使用DBCP 2。

由Java 6运行的应用程序应使用DBCP 1.4。

在Java 1.4下运行时应使用DBCP 1.3。


DBCP 2基于Commons Pool 2,与DBCP 1.x相比,提供了更高的性能,JMX支持以及众多其他新功能。 由于DBCP 2.x与DBCP 1.x不是兼容的,所以升级到2.x的用户应该知道Java包名称已经改变,以及Maven坐标。 用户还应该注意,一些配置选项(例如maxActive to maxTotal)已被重命名.


配置项说明

基本配置项

username

连接的用户名,通过驱动创建我们需要的连接

password

连接的密码,通过驱动创建我们所需要的连接.

url

连接的路径,通过驱动创建我们所需要的连接.

driverClassname

要使用的JDBC驱动程序的完全限定的Java类名称

connectionProperties

JDBC驱动建立连接时附带的连接属性属性的格式必须为这样:[属性名=property;]
注意:”username” 与 “password” 两个属性会被明确地传递,因此这里不需要包含他们。

比如:

connectionProperties=useUnicode=true;characterEncoding=utf8

事务相关配置项


数据源链接数量配置项

注意: If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.


连接健康情况维护和检查



缓存语句配置项

This component has also the ability to pool PreparedStatements. When enabled a statement pool will be created for each Connection and PreparedStatements created by one of the following methods will be pooled:

public PreparedStatement prepareStatement(String sql)public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

NOTE - Make sure your connection has some resources left for the other statements. Pooling PreparedStatements may keep their cursors open in the database, causing a connection to run out of cursors, especially if maxOpenPreparedStatements is left at the default (unlimited) and an application opens a large number of different PreparedStatements per connection. To avoid this problem, maxOpenPreparedStatements should be set to a value less than the maximum number of cursors that can be open on a Connection.


连接泄露回收配置项

If you have enabled removeAbandonedOnMaintenance or removeAbandonedOnBorrow then it is possible that a connection is reclaimed by the pool because it is considered to be abandoned. This mechanism is triggered when (getNumIdle() < 2) and (getNumActive() > getMaxTotal() - 3) and removeAbandonedOnBorrow is true; or after eviction finishes and removeAbandonedOnMaintenance is true. For example, maxTotal=20 and 18 active connections and 1 idle connection would trigger removeAbandonedOnBorrow, but only the active connections that aren’t used for more then “removeAbandonedTimeout” seconds are removed (default 300 sec). Traversing a resultset doesn’t count as being used. Creating a Statement, PreparedStatement or CallableStatement or using one of these to execute a query (using one of the execute methods) resets the lastUsed property of the parent connection.

Apache-DBCP数据库连接池解读相关推荐

  1. 使用 spring 集成 dbcp 数据库连接池到 Wowza 插件

    对于 Wowza 扩展插件,很可能需要连接数据库进行一些持久化查询操作,而且也很有可能把各种业务逻辑 bean 进行集中管理起来.本文结合集成 dbcp 数据库连接池到 Wowza 插件的案例,顺带介 ...

  2. springboot+dbcp数据库连接池

    springboot+dbcp数据库连接池 1,连接池配置文件 2,连接工具类 3,测试类测试连接 4,实际调用连接去同步数据 1,连接池配置文件 在resources目录下添加文件dbcp.prop ...

  3. JDBC实例--工具类升级,使用Apache DBCP连接池重构DBUtility,让连接数据库更有效,更安全...

    直接使用JDBC访问数据库时,需要避免以下隐患: 1. 每一次数据操作请求都需要建立数据库连接.打开连接.存取数据和关闭连接等步骤.而建立和打开数据库连接是一件既耗资源又费时的过程,如果频繁发生这种数 ...

  4. C3P0 与 DBCP 数据库连接池使用和比较

    博主声明: 转载请在开头附加本文链接及作者信息,并标记为转载.本文由博主 威威喵 原创,请多支持与指教. 本文首发于此   博主:威威喵  |  博客主页:https://blog.csdn.net/ ...

  5. DBCP 数据库连接池的实现

    DBCP数据源 DBCP 是 Apache 软件基金组织下的开源连接池实现,要使用DBCP数据源,需要应用程序应在系统中增加如下两个 jar 文件: Commons-dbcp.jar:连接池的实现 C ...

  6. 03_dbcp数据源依赖jar包,DBCP中API介绍,不同过dbcp方式使用dbcp数据库连接池,通过配置文件使用dbcp数据库连接池

     DBCP数据源 使用DBCP数据源,需要导入两个jar包 Commons-dbcp.jar:连接池的实现 Common-pool.jar:连接池实现的依赖库. 导入mysql的jar包. DBC ...

  7. 在Spring 中配置DBCP数据库连接池

    EmployeeDao 代码 import java.util.List; import java.util.Map;import org.springframework.context.Applic ...

  8. DBCP数据库连接池技术

    1 mysql版本 2 导入jar包版本,采用配置文件连接时,dbcp.properties文件放到src目录下 3 代码 public class DBCPTeset {@Testpublic vo ...

  9. Servlet+MySQL使用DBCP数据库连接池实现用户登录

    首先准备数据库数据和登录页面 创建user数据表并且插入几条数据 DROP TABLE IF EXISTS `user`; CREATE TABLE `user` (`id` int(11) NOT ...

最新文章

  1. java 语言实现的随机数生成算法
  2. Kafka如何对Topic元数据进行细粒度的懒加载、同步等待?
  3. user agent stylesheet对格式的影响
  4. Pci设备驱动:设备枚举
  5. magento 加速(.htaccess)
  6. 23. Leetcode 24. 两两交换链表中的节点 (链表-基础操作类-交换链表)
  7. 排序算法——各算法性能
  8. 前后台相互传值的方法概述
  9. SpringBoot教程
  10. 鸿蒙os2.0官网公测报名,鸿蒙OS2.0公测版测试资格报名-鸿蒙OS2.0公测版测试资格报名官网地址预约 -友情手机站...
  11. 枚举算法典型的三个例子
  12. VirtualBox 安装教程
  13. 小程序tabBar无效
  14. Python解析XML文档
  15. Easyui DataGrid 尾行添加合并行
  16. 饭饭的Selenium+xlwt笔记
  17. 和席慕容《一颗开花的树》
  18. spring管理事务管理1----------编程式(以下源码均为spring2.5.6)
  19. 2021年中国跨境电商行业发展现状及5G技术在中国跨境电商的应用分析:交易规模达142000亿元,同比增长13.6%[图]
  20. 【Unity】LineRenderer画运动轨迹

热门文章

  1. Ubuntu16.04运行VoxelNetRos
  2. python解矩阵方程_用Python代写的Numpy求解线性方程组
  3. Leetcode 322. 零钱兑换 (每日一题 20210824)
  4. Spark DataFrameDataSet
  5. 错误处理:安装torch-sparse、torch-spline、torch-scatter、torch-cluster
  6. 完美解答35K月薪的MySQL面试题(四)MySQL是如何加行锁的?
  7. 如何用Python写一个贪吃蛇AI
  8. 台式电脑可以连wifi吗_[Windows] wifi音箱:台式电脑也可以连接蓝牙音箱了
  9. LeetCode-链表-160. 相交链表
  10. 【LeetCode从零单排】No14.LongestCommonPrefix