2011-12-14 10 views
0

私のlinux(Ubuntu 11.10)でmysqlバージョン5.1を使用してこのコードに接続すると、うまく動作しますが、Windows上でアプリケーションを起動したいときは、mysql 5.5)例外をスローする:データベースにログインできない

org.hibernate.exception.GenericJDBCException: Cannot open connection 

どちらの場合も、私はlocalhostにログインしていました。 rootユーザーでログインしようとしました。私はパスワードが正しいことを完全に確信しています。 私はすべてのユーザーに新しい権限を与えようとしましたが、同じ例外でした。 私は試してみるが、私は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でConfigurationクラスを介してテストしましたが、これは同じ結果でした。

私の質問は、誰かが同じ問題を抱えて解決しているか、誰かがそれを解決する考えがありますか?

ありがとうございました

+0

は、データベースに接続できますコマンドラインを使用して?つまりmysql -u root -p –

+0

はい、私はそれを行うことができます。 –

+1

URLでlocalhostをハードコーディングできますか? –

答えて

1

あなたの認証情報を確認してください。 rootユーザーのパスワードが間違っています

+0

私はちょうどそれをチェックしたので、ユーザーのための私のパスワードは正しいです。 –

+0

例外では、ユーザーのrootがパスワードでデータベースに接続しようとしていて、MySQLが許可していないことが明らかになっています。 – WeMakeSoftware

+1

正しいデータベースに対して認証しているかどうかを確認してください。 – WeMakeSoftware

1

まず、win7にインストールされたmysqlにログインします。 mysqlインストールのbinフォルダにpromt.Moveコマンドを開きます。

C:線の上

-p \ mysqlの\ binに> mysql.exe -u rootがpassword.Inputパスワードの入力を要求し、あなたが正しくログインできるかどうかを確認します

関連する問題