/**
* 通过配置文件连接数据库
* @throws Exception
*/
//@Test
public void testConnection5() throws Exception {
// 读取配置文件的四个基本信息
InputStream is = ConnectionTest2.class.getClassLoader().getResourceAsStream("jdbc.properties");
Properties pros = new Properties();
pros.load(is);
//2.读取配置信息
String user = pros.getProperty("user");
String password = pros.getProperty("password");
String url = pros.getProperty("url");
String driverClass = pros.getProperty("driverClass");
//3.加载驱动
Class.forName(driverClass);
//4.获取连接
Connection conn = DriverManager.getConnection(url,user,password);
System.out.println(conn);
}
配置文件信息:
user=root
password=12341233
url=jdbc:mysql://localhost:3306/sys?serverTimezone=UTC
driverClass=com.mysql.cj.jdbc.Driver
为啥会报空指针的异常?