package com.JDBC;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;
public class JDBC_Dame {
public static void main(String[] args) throws Exception {
//导入jar包 druid-1.1.12.jar
//定义配置文件
Properties pro = new Properties();//创建properties对象
pro.load(new FileInputStream("src/druid.properties"));//加载键值对配置文件
DataSource dataSource = DruidDataSourceFactory.createDataSource(pro);//获取连接池对象
Connection connection = dataSource.getConnection();//获取数据库连接对象
System.out.println(connection);
}
}
配置文件
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/db1?useSSL=false&useServerPrepStmts=true&characterEncoding=utf8 username=root password=1234 initialSize=5 maxActive=10 maxWait=3000