0

When i connect with this code on my linux (Ubuntu 11.10) with mysql version 5.1 it works fine, but when i want to start my app on windows os (windows 7 with mysql 5.5) it throws exception:

org.hibernate.exception.GenericJDBCException: Cannot open connection

In both cases i was log in on localhost. I tried to log in on root user. I have complete certainty it was correct password. I tried to grand a all priviligates to new one user, but it was the same exception. Another option i was try was that i catch a GenericJDBCException and program gives me this:

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

I connect to database programmatically (via Hibernate AnnotationConfiguration):

annotationConfiguration = new AnnotationConfiguration();
annotationConfiguration.setProperty("hibernate.hbm2ddl.auto", "create");

// add annotatedClasses
annotationConfiguration.addAnnotatedClass(X.class);

annotationConfiguration.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.MySQLDialect");
annotationConfiguration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
annotationConfiguration.setProperty("hibernate.connection.url", "jdbc:mysql://" + host + ":3306/" + database);
annotationConfiguration.setProperty("hibernate.connection.username", userName);
annotationConfiguration.setProperty("hibernate.connection.password", password);
annotationConfiguration.setProperty("hibernate.connection.release_mode", "auto");
//annotationConfiguration.setProperty("hibernate.query.factory_class", "org.hibernate.hql.classic.ClassicQueryTranslatorFactory");
if (StaticConstants.DEBUG) {
    annotationConfiguration.setProperty("hibernate.show_sql", "true");
} else {
    annotationConfiguration.setProperty("hibernate.show_sql", "false");
}
annotationConfiguration.configure();
sessionFactory = annotationConfiguration.buildSessionFactory();
sessionFactory.close();

I use Hibernate version 3.6.7, but i tested it on Hibernate 3.6.8 via Configuration class and it was the same result.

So my question is has someone the same problem and solve it, or anyone have any idea to solve it?

Thanks

3
  • Can you connect to the database using commandline? i.e. mysql -u root -p Commented Dec 14, 2011 at 9:51
  • 1
    Can you try hardcoding localhost in the url. Commented Dec 14, 2011 at 9:58
  • no... but i should :) i check that but the same code works on linux Commented Dec 14, 2011 at 10:00

2 Answers 2

1

check your credentials. your password for user root is wrong

Sign up to request clarification or add additional context in comments.

8 Comments

the exception clearly says that a user root has tried to connect to the database with some password and MySQL didn't allow it
Check if you're authenticating against proper database. You may have several instances running in your environment
yes, you have right, but maybe there is some problem with hibernate or something like that - thats why i wrote here.
I mean several instances of MySQL running. This is not a code problem, but rather a configuration problem. Did you flush the privileges after you've granted them? Did you try to restart Mysql after granting the privileges?
try the following: connect from command prompt and issue commands manually: create user testUser grant all privileges on database_name.* to 'testUser'@* identified by 'testPassword' // note the star at the end of the database name flush privileges // this is really important Change your java code to reflect the new credentials. Launch the app.
|
1

First try login into mysql installed on win 7 from the command prompt. Open command promt.Move to the bin folder of mysql installation.

C:\mysql\bin>mysql.exe -u root -p

Above line will prompt for password.Input password and see if you are able to login correctly

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.