前言
Druid数据库连接池学习笔记
导入jar包
- 将
druid-1.2.12.jar
导入到lib
目录下
创建配置文件
1 2 3 4 5 6 7 8 9 10
| druidClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql:// username= password=
initialSize=5
maxActive=5
maxWait=3000
|
获取数据库连接
src/druid.properties
:指定配置文件存放目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public class Demo { public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.load(new FileInputStream("src/druid.properties")); DataSource dataSource = DruidDataSourceFactory.createDataSource(prop); Connection connection = dataSource.getConnection(); System.out.println(connection); } }
|
完成
参考文献
哔哩哔哩——黑马程序员