当前位置:网站首页>Use of database connection pool and Druid
Use of database connection pool and Druid
2022-04-21 23:35:00 【Jing<& gt;】
1. Concept : It's actually a container ( aggregate ), To be responsible for the distribution of 、 Manage database connections ; Allow applications to reuse an existing database connection , Instead of building a new ;
When the system is initialized , The container is created , Some connection objects will be requested in the container , When the user comes to access the database , Get the connection object from the container , After the user visits , The connection object is returned to the container .
2. benefits : Resource reuse , Improve system response speed , Avoid missing database connections .
3. Realization :
Ⅰ. Standard interface :DataSource javax.sql Under bag
Method :
Get the connection :getConnection()
Return connection :Connection.close(). If the connection object Connection It's taken from the connection pool , So called Connection.close() Method , The connection will no longer be closed . But return the connection
Ⅱ. Generally we don't realize it , There are database vendors to implement
Most commonly used Druid: Database connection pool implementation technology , Provided by Alibaba
The following figure shows the configuration file , Written in src in

1. step :
1. Import jar package druid-1.0.9.jar
2. Define configuration file :
* yes properties Formal
* You can call it anything , It can be placed in any directory
3. Load profile .Properties
4. Get database connection pool object : From the factory DruidDataSourceFactory
5. Get the connection :getConnection
* Code :
//3. Load profile
Properties pro = new Properties();
InputStream is = DruidDemo.class.getClassLoader().getResourceAsStream("druid.properties");
pro.load(is);
//4. Get connection pool object
DataSource ds = DruidDataSourceFactory.createDataSource(pro);
//5. Get the connection
Connection conn = ds.getConnection();

版权声明
本文为[Jing<& gt;]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212332234371.html
边栏推荐
- Man machine verification reCAPTCHA V3 complete instructions
- leetcode:386. Dictionary order
- 340 leetcode valid Letter ectopic words
- How to build an observable system that can "evolve continuously"| QCon
- 如何构建一个可“持续演进”的可观测体系?| QCon
- SolidWorks怎么设置运动行程和角度
- Amazing, 4 high-quality software full of surprises, feel more comfortable to use
- GAN网络笔记 MATLAB实现
- 自定义登录成功处理
- The element clicked by selenium is blocked and cannot be operated
猜你喜欢

CentOS7使用yum安装MySQL——指定版本

6. Hiérarchie des protocoles et modèle de service (clé)

如何构建一个可“持续演进”的可观测体系?| QCon

A collection of large factories and face classics. Do you know these knowledge points

iotdb权限管理

【acwing】1125. 牛的旅行***(floyd)

JDBC概念 在idea里创建JDBC项目步骤

Why don't MySQL use select * as query criteria? (continuously updated)

【接口测试基础】第四篇 | 接口测试流程及接口文档解析

数据库连接池和Druid的使用
随机推荐
Selection and evolution of microservices under cloud native architecture
找出大于X的第一个质数(DAY 42)
DetNet: A Backbone network for Object Detection
341-Linux 连接数据库
[H.264] H.264 parsing tool, web parsing
入参有汉字,报错500,服务器内部错误
#1143 Longest Common Subsequence
MYSQL 为什么不要使用SELECT * 作为查询条件?(持续更新)
叹为观止,4款惊喜满满的高质量软件,使用起来倍感舒适
信噪比和信干噪比
MySQL存储过程用法--含练习题
pytorch(五)——笔记
拼多多店铺怎么选择资源位,怎么报名活动,什么活动对店铺利益最大?
Robot OS驱动开发
Developing Cami community system with ThinkPHP
341 Linux connection database
分布式gns3
Find the first prime number greater than x (day 42)
leetcode:440. 字典序的第K小数字
[reprint] postman omysql connection database