Hibernate-mysql常見問題
url地址填寫
<!-- 配置連線資料庫mysql的基本資訊 -->
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url"
<!-- 若加上IP則前面的是兩條斜槓,若不加IP則是三條斜槓 -->
<!-- <property name="connection.url">jdbc:mysql:///hibernate5?characterEncoding=utf8</property> -->
- eclispe反編譯安裝
Decompiler
- hibernate工具安裝
勾選Hibernatetools,安裝後
File - New - other
4.JUnit4測試用例
有時候JUnit5會有不相容的問題
有些不相容問題,可以右鍵
Run As - Run Configuration
5.測試用例mysql失敗原因
<!-- 配置Hibernate的基本資訊 -->
<!-- Hibernate所使用的資料庫方言 -->
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
Hibernate異常總結:org.hibernate.exception.SQLGrammarException: could not execute statement
- mysql密碼識別,字元不對
需要指定字符集
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate5?characterEncoding=utf8</property>
- 程式碼