在resources下创建一个properties文件
jdbcdriver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/one
username=root
password=admin123
代码创建数据源
ResourceBundle resourceBundle = ResourceBundle.getBundle("jdbc");
String driver = resourceBundle.getString("jdbcdriver");
String url = resourceBundle.getString("url");
String username = resourceBundle.getString("username");
String password = resourceBundle.getString("password");
// 创建c3p0数据源
ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource();
comboPooledDataSource.setDriverClass(driver);
comboPooledDataSource.setJdbcUrl(url);
comboPooledDataSource.setUser(username);
comboPooledDataSource.setPassword(password);
// 打印输出,测试连接效果
Connection connection = comboPooledDataSource.getConnection();
System.out.println(connection);
connection.close();