2010-12-13 103 views
0

我需要一些幫助來設置Hibernate。我已經安裝了eclipse和mysql,並編寫了一個簡單的程序來在db中存儲一個表。但我得到以下例外需要幫助設置休眠

Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection 
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92) 

基本上我創建了一個名爲聯繫數據庫,裏面有一個名爲在MySQL中的聯繫表。我的配置文件如下

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
    <property name="hibernate.connection.url">jdbc:mysql://localhost/contact</property> 
    <property name="hibernate.connection.username">anandi</property> 
    <property name="hibernate.connection.password">anandi</property> 
    <property name="hibernate.connection.pool_size">10</property> 
    <property name="show_sql">true</property> 
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property> 
    <property name="hibernate.hbm2ddl.auto">update</property> 

以上是好嗎?用戶和密碼是正確的,但我有一些關於屬性name =「hibernate.connection.url參數的疑問。任何人都可以幫助我爲什麼我得到異常和應該是相同的修復。我花了一段時間。關於這一點,所以任何幫助,將不勝感激

問候, 開發

+0

您的數據庫是否在localhost上運行,並且具有聯繫模式? – 2010-12-13 18:48:09

+0

是的,我已經在我的本地機器上安裝了mysql。我創建了一個名爲contact的數據庫,並且我還在這個數據庫中創建了一個名爲contact的表。任何幫助什麼是缺少的? – user496934 2010-12-14 05:41:31

+0

基本上我已經在以下路徑中安裝了mysql:C:\ Documents and Settings \ All Users \ Application Data \ MySQL \ MySQL Server 5.1,數據庫物理地存儲在C:\ Documents and Settings \ All Users \ Application Data \ MySQL中\ MySQL Server 5.1 \ data \ contact。我應該在connection.url中提供完整的路徑嗎? – user496934 2010-12-14 05:52:30

回答

3

在您的url屬性非要在年底你的數據庫名稱在你的情況下,它是聯繫(聯繫不上) JDBC。: mysql:// localhost/Contact Mysql中的數據庫名稱區分大小寫

0

如果您使用的是標準MySQL安裝,請指定端口號r連接:

jdbc:mysql://localhost:3306/Contact 
+0

如果mysql服務器在默認端口3306上運行,則不需要端口號 – Gaurav 2015-09-17 12:53:48