java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

前端 未结 1 689
予麋鹿
予麋鹿 2020-12-17 06:41

Why do you think this function gives me always null?? Using another login program, which has the same code structure, it works greatly. My DBURL is jdbc:mysql://localhost:88

相关标签:
1条回答
  • 2020-12-17 07:13

    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    As you have mentioned problem is with creating connection with the database itself. Statement

    con = DriverManager.getConnection(DatabaseURL, userName, password);
    

    is throwing exception which is getting caught at

    catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }   
    

    after which you are returning dbresult which you have initialized to null(which you have to as it is a local variable). So the problem is that you are unable to connect to your db due to authentication.

    On your machine where (localhost in ur case ) run the following command from console

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
    
    0 讨论(0)
提交回复
热议问题