Exception: "Access denied for user ''@'localhost' (using password: NO)"
In this code, an SQLException is thrown when trying to establish a connection to a MySQL database. The error message indicates that the user trying to connect to the database is not authorized.
Specifically, the code in the MainApp class attempts to connect to the database using the DriverManager.getConnection method, providing the URL, username, and password. However, the error message suggests that the user with an empty username is trying to connect using the password "NO," which is incorrect.
Solution:
To resolve this issue, verify the following:
Once you have verified these steps, the code should be able to establish a successful connection to the MySQL database without the "Access denied" error.
The above is the detailed content of Why am I getting 'Access denied for user ''@'localhost' (using password: NO)' when connecting to MySQL?. For more information, please follow other related articles on the PHP Chinese website!