I\'m having troubles with my project , it involves JDBC
and Mysql
connection .
When I do the following :
private Statement m_
Either the username/password is wrong or the user is missing privileges to access the schema/table. Grant privileges using
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION
TO check if mysql has a password, go to the directory where you installed mysql, and in the bin directory try to bring up mysql prompt using
./mysql –u root mysql
If the login goes through without any problem, it means no password is set.
You can use mysqadmin script to set/reset password.
./mysqladmin –u root password "password string"
I encounter the same error, this is how I fixed it:
I used DriverManager class like this:
Class.forName("com.mysql.jdbc.Driver");
Connection Hello = DriverManager.getConnection("jdbc:mysql://YOUR-URL-HERE", "USERNAME", "PASSWORD");
And that's it. Also, when selecting a table, remenber to put the DB name first, like:
"DB_NAME.TABLE_NAME".
Looks like you've only just installed mysql. Run mysql_secure_installation
. It will prompt you for a root password, among other things.
I had the same problem. You need to set a password for the user. Go to the mysql console .
$ mysqladmin -u root password myFirstpassword
Then change your password in the java program