druid数据池连接技术
1.下载dbutils jar包导入lib
![image-20210525172845865](https://i-blog.csdnimg.cn/blog_migrate/73b17b67fb5139b35d8a20ff085d261f.png)
2.druid.properties
# druid.properties文件的配置
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
username=root
password=shan5211314..
# 初始化连接数量
initialSize=5
# 最大连接数
maxActive=10
# 最大超时时间
maxWait=3000
3.DruidTest
package com.shan3.databaseConnection;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.shan3.databaseConnection.utils.JDBCUtils;
import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
public class DruidTest {
@Test
public void testGetConnection() throws Exception {
Properties pros = new Properties();
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("druid.properties");
pros.load(is);
DataSource source = DruidDataSourceFactory.createDataSource(pros);
Connection conn = source.getConnection();
System.out.println(conn);
Connection conn1 = JDBCUtils.getConnectionDruid();
System.out.println(conn1);
}
}