-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDruid_.java
More file actions
30 lines (27 loc) · 1.1 KB
/
Druid_.java
File metadata and controls
30 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.charlie.jdbc.datasource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;
public class Druid_ {
@Test
public void testDruid() throws Exception {
// 1. 加入 Druid jar包
// 2. 加入 配置文件 到 src 目录下
// 3. 创建 Properties 对象,读取配置文件
Properties properties = new Properties();
properties.load(new FileInputStream("src\\druid.properties"));
// 4. 创建一个指定参数的数据库连接池
DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
long start = System.currentTimeMillis();
for (int i = 0; i < 5000; i++) {
Connection connection = dataSource.getConnection();
// System.out.println("连接成功...");
connection.close();
}
long end = System.currentTimeMillis();
System.out.println("Druid连接池,连接5000次耗时:" + (end - start)); // 260
}
}