Java – Keep getting access denied for root at localhost password yes even though I supply correct login info

javajavadbMySQLnetbeans

I keep getting:

Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials – 2.0.1 (Build
b09d-fcs (12/06/2007))):
oracle.toplink.essentials.exceptions.DatabaseException Internal
Exception: java.sql.SQLException: Access denied for user
'root'@'localhost' (using password: YES)

But my project code connection info and the MySQL Database have the same information – therefore I'm suppliying the correct login info. Why does it keep saying my password is wrong. I am on local host and my username is root and there's no password.

Here's the code for project variables I use:

static final String host = "jdbc:mysql://localhost:3306/myDb";
    static final String uName = "root";
    static final String uPass = "";
    static final String query = "SELECT * FROM customers";
...
    Connection con = DriverManager.getConnection( host, uName, uPass );

Best Answer

Is the root password set for localhost? It's been awhile, but localhost is not always the same as 127.0.0.1, and root's password may not have localhost as the default associated host.