導(dǎo)入druid包
package druid;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;
/*
* Druid數(shù)據(jù)庫連接池
* */
public class DruidDemo {
? ?public static void main(String[] args) throws Exception {
? ? ? ?//1.導(dǎo)入jar包
? ? ? ?//2.定義配置文件
? ? ? ?//3.加載配置文件
? ? ? ?Properties prop =new Properties();
? ? ? ?prop.load(new FileInputStream("jdbc_demo/src/druid.properties"));
? ? ? ?//4.獲取連接池對象
? ? ? ?DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
? ? ? ?//5.獲取數(shù)據(jù)庫連接
? ? ? ?Connection connection = dataSource.getConnection();
? ? ? ?System.out.println(connection);
? ?}
}

注意;
driverClassName=com.mysql.cj.jdbc.Driver
標(biāo)簽: