当前位置:网站首页>数据库连接池
数据库连接池
2022-08-07 20:15:00 【张 明明】
数据库连接池
Druid为监控而生的数据库连接池,它是阿里巴巴开源平台上的一个项目。Druid是Java语言中最好的数据库连接池,Druid能够提供强大的监控和扩展功能.它可以替换DBCP和C3P0连接池。Druid提供了一个高效、功能强大、可扩展性好的数据库连接池。
作者:索伦x
链接:https://www.jianshu.com/p/6e01354213d8
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
数据库连接是很大的资源项,可以由数据库连接池统一调配。
写一下Driud的入门
第一步要先导入Druid的jar包。
import java.sql.Connection;
import java.util.Properties;
/** * Druid数据库连接池 */
public class DruidDemo1 {
public static void main(String[] args) throws Exception {
//1配置jar包
//2加载配置文件
Properties properties=new Properties();
properties.load(new FileInputStream("jdbc-01\\src\\druid.properties"));//配置文件的相对路径
//获取连接
DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
Connection connection = dataSource.getConnection();
/** * 获取了connection后就可以写sql操作数据库了 * 可以选择statement或者preparestatement来执行sql */
System.out.println(connection);
//下面可以输出当前项目的根路径,由此可以知道文件的相对路径
System.out.println(System.getProperty("user.dir"));
}
}
properties.load(new FileInputStream(“jdbc-01\src\druid.properties”));//配置文件的相对路径
这个是我的配置文件路径。
看一下配置文件
driverClassName=com.mysql.jdbc.Driver//这个用来加载驱动的。
url,username,password是和之前一样的。
边栏推荐
- 全球首个!元宇宙安全极客大会来了
- Mysql 45讲学习笔记(二十七)主库出问题了
- centos 7.7 二进制安装mysql8.0.29
- After failing n times, I have summed up 5 crawler disguise techniques!
- [C# language] DataGridView hides rows and columns
- Better and more modern terminal tool than XShell!
- What is a split brain
- Tcache Stashing Unlink Attack 原理详解
- 【C#语言】DataGridView修改选中行颜色
- 魔众API支持接口数量配额邮件告警
猜你喜欢

Pytest学习-日志模块

高并发+海量数据下如何实现系统解耦?【上】

渥太华大学:Hao Zhou | 用于6G中基于深度强化学习的波束管理的联合传感和通信

Jumping Stone (Dynamic Programming)

基于 Next.js实现在线Excel

Tcache Stashing Unlink Attack 原理详解

How to open IntelliSense configuration in vscode

After failing n times, I have summed up 5 crawler disguise techniques!

Typecho反序列化漏洞寻找思路

ros(27):roscore、ros master、ros::init()、roslaunch
随机推荐
线性预测和自回归建模
5分钟的时间制作一个反弹球游戏
高并发+海量数据下如何实现系统解耦?【上】
数学 余式定理 简介
【C#语言】DataGridView绘制行号
[C# language] DataGridView modify the color of the selected row
DevEco Studio Configuration: Custom Header Code Comments
基于FTP协议的文件上传与下载
[The Beauty of Software Engineering - Column Notes] "One Question and One Answer" Issue 4 | 14 Common Problem Solving Strategies for Software Development
After failing n times, I have summed up 5 crawler disguise techniques!
AAAI2020】阿里DMR:融合Matching思想的深度排序模型
MONAI_Label installation trial
Introduction to functions - understanding of the container_of macro
测试工程师如何做到初级测试管理(个人思考)?
Leetcode 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
章节小测
Salesforce中国区解散,谁是替代的最佳选择?
Mysql.索引篇 一次搞清楚八股文
利物浦大学:Tudor Jianu | CathSim:一个用于自主插管的开源模拟器
[C# language] DataGridView draws row numbers