import java.sql.*;
public class JDBCTest01{
public static void main(String[] args){
try{
Driver driver = new com.mysql.jdbc.Driver();
DriverManager.registerDriver(driver);
String url = "jdbc:mysql://localhost:3306/bjpowernode";
String user = "root";
String password = "asd1234567";
Connection conn = new DriverManager.getConnection(url,user,password);
System.out.println("数据库连接对象:" + conn);
}catch(SQLException e){
e.printStackTrace();
}
}
}
报错找不到符号Connection conn = new DriverManager.getConnection(url,user,password);
然后我上idea上看,结果是调用getConnection方法报红,不知道什么原因
getConnection是DriverManager类中的静态方法,直接通过类名.方法名调用就可以了,不用加new