當我與我的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