Javaweb-数据库连接池




package DRUID;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.util.Properties;

public class DruidDemo {
public static void main(String[] args) throws Exception {
//1.导包
//2.定义配置文件
//3.加载配置文件
Properties prop = new Properties();
prop.load(new FileInputStream("./src/druid.properties"));
//4.获取连接池对象
DataSource ds = DruidDataSourceFactory.createDataSource(prop);
//5.获取数据库链接
Connection conn = ds.getConnection();
System.out.println(conn);
}
}

posted @ 2024-09-09 18:22  wangyin0425  阅读(3)  评论(0编辑  收藏  举报