@Test
public void test5() throws Exception {
InputStream is = ConnectionTest.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties properties = new Properties();
properties.load(is);
String user = properties.getProperty("user");
String password = properties.getProperty("password");
String url = properties.getProperty("url");
String driver = properties.getProperty("driver");
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
System.out.println(connection);
}
路径如图,jdbc.properties放在了当前module下
获取到is后,先输出看一下,如果没有信息说明ConnectionTest.class.getClassLoader().getResourceAsStream()没有获取对应的类,你需要重新看一下使用方法