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