我一直在搞乱 JDBC 并尝试连接到我创建的测试数据库,但是我不断收到此错误:
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
我不知道如何解决这个问题,我尝试了两种代码变体,它们都在这里抛出相同的错误:
public static void main(String[] args){
Connection connection = null;
Statement statement = null;
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/feedback? user=root&password=1234");
System.out.print("Connected");
connection.close();
System.out.println("Closed");
}catch(Exception e){
System.out.println("Error: " + e);
}
}
也:
public class JDBC {
public static void main(String[] args) throws SQLException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "1234";
System.setProperty(driver, "");
try {
DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
System.out.println("Error: " + e);
}
}
}
谁能给我一个关于从这里开始的指示?