各位大 佬帮我看看什么问题?数据库驱动死活连不上,代码如图,怎么解决啊,急
不用回答不用回答
public class JDBCUtil {
public static Connection getConnection() throws Exception {
// InputStream is = ClassLoader.getSystemResourceAsStream("jdbc.properties");
// Properties pros = new Properties();
// pros.load(is);
// String username = pros.getProperty("username");
// String password = pros.getProperty("password");
// String url = pros.getProperty("url");
// String driverClass = pros.getProperty("driverClass");
String username = "root";
String password = "root";
String driverClass = "com.mysql.cj.jdbc.Driver";
//2.加载驱动
Class.forName(driverClass);
//3.获取连接
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
//关闭数据库的连接
public static void closeResource(Connection conn, Statement ps) {
try {
if(ps != null){
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
//关闭数据库的连接
public static void closeResource(Connection conn, Statement ps, ResultSet rs) {
try {
if(ps != null){
ps.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs != null){
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}