当我与我的Linux(Ubuntu 11.10)与MySQL版本5.1上的代码连接它工作正常,但是当我想在Windows操作系统启动我的应用程序(Windows 7的MySQL 5.5)它抛出异常:Hibernate,JDBC,Mysql,无法登录到数据库
org.hibernate.exception.GenericJDBCException: Cannot open connection
在这两种情况下我都在本地主机上登录。 我试图登录到root用户。我完全确定这是正确的密码。 我试图盛大所有priviligates新的用户,但它是同样的例外。 另一种选择,我是尝试是,我赶上GenericJDBCException
和节目给了我这样的:
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
我连接到数据库编程(通过休眠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();
我使用Hibernate 3.6.7版,但我通过配置类在Hibernate 3.6.8上测试了它,结果相同。
所以我的问题是有人有同样的问题和解决它,或任何人有任何想法解决它?
谢谢
你能连接到数据库使用命令行?即mysql -u root -p – 2011-12-14 09:51:44
是的,我可以做到。 – 2011-12-14 09:52:57