access denied exception using connector/j mysql
I am using mysql and connector/j, trying to connect to the database on my localhost, following this tutorial. Here is a part of the code I am using:
String url = "jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url,"root", "");
And I am always getting this exception: java.sql.SQLException: Access denied for user 'root'@'localhost' 开发者_如何学编程(using password: NO)
There is no default password for the root, and I did not changed it. I can connect to the db from the mysql prompt with the same parameters. I added a new database and user from prompt, tried to connect with that user and pwd, and still get the access denied exception. Do somebody know what could be the problem?
seems like you got the problem describe in this thread
There is no default password for the root, and I did not changed it.
Perhaps someone or something else did!
I suggest that you go through the procedure of resetting the MySQL root account's password ... and this time set it to something.
The instructions for resetting the root password are in Appendix C 5.4.1 of the manual (MySQL 5.0 and later). For example, here.
Looking at what you have done everything seems correct.
String url = "jdbc:mysql://localhost:3306/mysql";
Is the name of your database mysql? I feel that is where you are making the mistake. Change the mysql after localhost:3306/ to the name of your db
精彩评论