"Fixing Exception: java.sql.SQLException: Access Denied for User with Empty Credentials"
Question:
An exception with the message "java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)" is encountered while trying to connect to a MySQL database. All attempts to change the user's password, grant permissions, or reconnect have failed. What is the root cause of this error?
Answer:
The provided Java code contains a discrepancy in the main method call:
public void main(String[] args) throws SQLException
This method is likely part of a different class, "com.mysql.cj.jdbc.admin.TimezoneDump," which also defines a main method. As a result, Eclipse may be running this incorrect class instead of the intended "MainApp" class.
To resolve this issue, you can manually指定 which class to run:
This action will instruct Eclipse to execute the "MainApp" class, which should successfully connect to the database without the access denied error.
The above is the detailed content of Why Does My Java Code Throw an 'Access Denied' Error When Connecting to MySQL?. For more information, please follow other related articles on the PHP Chinese website!