public void getConnection() throws Exception {
//1.获取数据库连接信息
InputStream is = ConnectionTest.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
properties.load(is);
String driver = properties.getProperty("driver");
String url = properties.getProperty("url");
String user = properties.getProperty("user");
String password = properties.getProperty("password");
//2.加载注册数据库驱动
Class.forName(driver);
//3.获取数据库连接
Connection connection = DriverManager.getConnection(url,user,password);
System.out.println(connection);
}
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test
user=root
password=admin