package druid; /* *druid数据连接池 * */ import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSource; import java.io.FileInputStream; import java.io.FileReader; import java.sql.Connection; import java.util.Properties; public class DruidDemo { public static void main(String[] args) throws Exception { //1.导入jar包 //2.定义配置文件 //3.加载配置文件 Properties prop = new Properties(); //获取数据库的位置信息,加载数据库 prop.load(new FileInputStream("F:\\Develop\\code\\Demo2\\src\\druid.txt")); //4.获取连接池对象 DataSource dataSource = DruidDataSourceFactory.createDataSource(prop); //5.获取连接池对象Connection Connection connection = dataSource.getConnection(); System.out.println(connection); } }
标签:java,数据库,Druid,druid,import,prop,Properties,连接池 From: https://www.cnblogs.com/Karl-hut/p/17482513.html