0

I made connection between my program and a database in phpMyAdmin, this is the connection method:

public Connection getConnection() throws SQLException{
    Connection con=null;
    con=DriverManager.getConnection("jdbc:mysql://localhost/testdb"," 
 ","");
    return con;
}

And I got the following exception: enter image description here

  • 1
    Does this answer your question? [java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)](https://stackoverflow.com/questions/11922323/java-sql-sqlexception-access-denied-for-user-rootlocalhost-using-password) – Dren Feb 20 '21 at 19:48
  • Please don't post exception stacktraces, post them as code-formatted **text**. This improves readability, and discoverability – Mark Rotteveel Feb 21 '21 at 08:28

1 Answers1

2

The exception message tells you all you need to know: the reason you're getting an error is because the credentials (username and password) you are using are not allowed to access the database you are trying to connect to.

You need to log in to the database first and grant access using those credentials.

Mike Dinescu
  • 54,171
  • 16
  • 118
  • 151