问题遇到的现象和发生背景
java连接mysql时出现条件 'stmt != null' 始终为 'false'
问题相关代码,请勿粘贴截图
final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
final String DB_URL = "jdbc:mysql://localhost:3307/work?useSSL=false&serverTimezone=UTC";
final String USER = "root";
final String PASS = "262412";
Connection conn = null;
Statement stmt = null;
try {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException ignored) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
运行结果及报错内容
java.lang.NullPointerException