- Notifications
You must be signed in to change notification settings - Fork7
The jdbc pool for java.(java 手写 jdbc 数据库连接池实现)
License
NotificationsYou must be signed in to change notification settings
houbb/jdbc-pool
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
jdbc-pool 是一款简化版的 jdbc-pool 实现。
第二节从零开始手写 mybatis(二)mybatis interceptor 插件机制详解
第三节从零开始手写 mybatis(三)jdbc pool 从零实现数据库连接池
第四节从零开始手写 mybatis(四)- mybatis 事务管理机制详解
学习 jdbc-pool 的原理
便于拓展自己的数据库工具
基本的数据库连接池实现
自动适配 jdbc 驱动类
支持各种场景对于连接的校验
jdk 1.7+
maven 3.x+
<dependency> <groupId>com.github.houbb</groupId> <artifactId>jdbc-pool</artifactId> <version>1.7.0</version></dependency>
JdbcPoolBsjdbcPoolBs =JdbcPoolBs.newInstance() .username("root") .password("123456") .url("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8");DataSourcepooled =jdbcPoolBs.pooled();DataSourceunPooled =jdbcPoolBs.unPooled();
UnPooledDataSourcesource =newUnPooledDataSource();source.setDriverClass("com.mysql.jdbc.Driver");source.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8");source.setUser("root");source.setPassword("123456");Connectionconnection =source.getConnection();
PooledDataSourcesource =newPooledDataSource();source.setDriverClass("com.mysql.jdbc.Driver");source.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8");source.setUser("root");source.setPassword("123456");source.setMinSize(1);// 初始化source.init();Connectionconnection =source.getConnection();System.out.println(connection.getCatalog());Connectionconnection2 =source.getConnection();System.out.println(connection2.getCatalog());
[DEBUG] [2020-07-18 10:50:54.536] [main] [c.g.h.t.p.d.PooledDataSource.getFreeConnection] - 从连接池中获取连接test[DEBUG] [2020-07-18 10:50:54.537] [main] [c.g.h.t.p.d.PooledDataSource.getConnection] - 开始扩容连接池大小,step: 1[DEBUG] [2020-07-18 10:50:54.548] [main] [c.g.h.t.p.d.PooledDataSource.getConnection] - 从扩容后的连接池中获取连接test第一次默认直接从线程池中获取,第二次为重新创建的信息。
根据 url 自动识别 driverClass
添加获取的等待
添加设置为繁忙的状态 check
添加日志替代 sout
添加 validQuery, testOnBorrow, testOnReturn, testWhileIdle
添加 filter-chain
JMX 添加各种监听的属性
添加监控页面实现
添加 druid/mybatis??/commons-pool 等常见的数据源
About
The jdbc pool for java.(java 手写 jdbc 数据库连接池实现)
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published