数据库连接成功了,但在用preparedstatement连接时出现空指针
package edu.hebeu.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class GetConn {
Connection conn=null;
public Connection getConnection() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String ur1="jdbc:mysql://localhost:3306/sjk?serverTimezone=UTC&useSSL=false";
Connection conn=DriverManager.getConnection(ur1, "root","root");
if(conn!=null)
{
System.out.println("数据库连接成功!");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}