0
我一直在用JDBC瞎搞,并试图连接到我创建了一个测试数据库,但我不断收到此错误:MySQL和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);
}
}
}
任何人都可以给我一个指向从哪里继续?
消息非常具有描述性,它似乎是用户标识,密码(或)两者的组合都不匹配。 – kosa
当我安装MySQL时,它要求给root一个我设置为“1234”的密码,显然没有引号。 – user123
尝试使用mysql工作台(或)sql编辑器登录并检查登录是否正常工作 – kosa