0
正如標題所說,我使用Hibernate ORM,並且每當我嘗試使用Č或save保存某些內容時,hibernate會拋出「無法執行查詢」錯誤。我使用utf8,Š,Ž,Đ字符工作得很好。我迷路了......這裏是CFG文件:Hibernate DataException保存Č,Ć字符
<property name="connection.url">jdbc:mysql://localhost:3306/eventi_orm</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="show_sql">true</property>
<property name="format_sql">false</property>
這裏是輸出:
Exception in thread "AWT-EventQueue-0" org.hibernate.exception.DataException: could not execute statement
...
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xC4\x87' for column 'name' at row 1
「數據截斷」... UTF-8字符具有可變長度。 BTW數據庫(mysql)應該被精確配置,因爲排序和其他問題。在古代我們在ASCII數據庫列中存儲utf-8 strigs,類似的問題發生 –
我相信這是一個相同的問題:https://stackoverflow.com/questions/2108824/mysql-incorrect-string-value-error-when-保存unicode字符串在Django – Andremoniy
可能重複的[MySQL的不正確的字符串值錯誤時保存unicode字符串在Django中](https://stackoverflow.com/questions/2108824/mysql-incorrect-string-value-error -when-save-unicode-string-in-django) – Guillotine