1 public class DBCPUtils { 2 3 /** 4 * DBCP数据库连接池 5 */ 6 private static DataSource source; 7 8 static { 9 try { 10 Properties pros = new Properties(); 11 FileInputStream is = new FileInputStream(new File("src/dbcp.properties")); 12 pros.load(is); 13 source = BasicDataSourceFactory.createDataSource(pros); 14 } catch (Exception e) { 15 16 } 17 } 18 19 public static Connection getConnection(){ 20 Connection conn = source.getConnection(); 21 return conn; 22 } 23 }