MySQL和JDBC错误登录



我一直在与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);
    }
  }
}

任何人都可以给我一个指针,从这里去哪里?

消息几乎具有描述性,似乎用户ID,两者的密码(或)组合不匹配

编辑:

屏幕截图后与程序中的错误端口定义有关。

尝试这个 -

  1. 重置root的密码。检查您的连接URL。
  2. 如果#1不起作用,那么而不是使用root,请创建具有完整访问权限的新用户。

最新更新