wood burning stoves 2.0*
The moose likes JDBC and the fly likes java.sql.SQLException Access Denied Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException Access Denied" Watch "java.sql.SQLException Access Denied" New topic
Author

java.sql.SQLException Access Denied

Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi guys

Sorry to ask a basic 'set-up' problem, but I've been trying to sort this out for hours with no success.

I am getting the following message when trying to run a program:

java.sql.SQLException Access denied for user 'root@localhost' (using password 'Yes')

I have queried the user table several times in mySQL to find out the password for the host 'localhost' and user 'root'. It as a really long series of numbers and letter starting with a star.

When I change the password, the long series of numbers and letters change.

In the getConnection method in my code, I have tried to pass a string that have changed the password to such as 'secret' and also the whole of the number shown in the mySQL interface eg. '*4E65567ABDB5135D0CFD9A70B3032C179A49EE7'. I have also tried with the password parameter set to NULL.

I still get the same message whatever I do (apart from the (using password 'Yes') bit changes.

Please could someone tell me why the system is denying my program access to the database and what I can do about it.

Thanks in advance.

Regards

Joe Lemmer

Here's my code by the way:



OCPJP 85%
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38508
    
  23
Not sure how you are passing your password, but what is stored in the database is something like an MD5 of the password. You write a password, eg "OpenSesame" but the database receives it in a hashed format which comes out as ab29d03bd9ce8780ad9ec9b76570abd36297894. Or something a bit like that.

Or something like that. So you will have to pass 'OpenSesame' or password('OpenSesame') or similar. You can't pass ab29d03bd9ce8780ad9ec9b76570abd36297894 because that will be rehashed to 9384abd9834dfc98acd73485768ebd or something.

I can't see anything wrong just eyeballing your code, so try opening your database from the command line or its GUI interface and see whether you can log on from there.

Also go through the MySQL handbook (probably �19) and check you have got the correct spelling for your connection String, and make sure you do actually have a database called soup.
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Campbell you are a legend!!

I wasn't following instructions properly as usual. The tutorial had soup as the database name and I've used a totally different name.

I really appreciate your help. I've saved loads of money not buying that sledgehammer!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Sorry for bumping a pretty old thread. I received the same exception and my db, username & password all were correct. I executed the below grant statement and it fixed the issue.
 
Consider Paul's rocket mass heater.
 
subject: java.sql.SQLException Access Denied