2
在我們的數據庫中,我們存儲everyting與字符集UTF8,並使用COLLATE utf8_general_ci
。整理「utf8_general_ci」是無效字符集「LATIN1」 - 即使UTF8是建立
然而,從一個表中查詢數據時,我們總是會收到以下異常:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:111)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
... 120 more
我們交叉檢查的一切,我們可以想像:
SHOW VARIABLES LIKE '%char%';
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
以及
SHOW VARIABLES LIKE '%collation%';
collation_connection utf8_general_ci
collation_database utf8_general_ci
collation_server utf8_general_ci
另外
SELECT * FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA = "ourscheme" and Character_set_name <> "utf8";
(empty result)
我們確保客戶端連接使用utf-8。
我們沒有想法。表格和列(s)似乎設置正確。
我們還試圖明確使用COLLATE查詢:
...table.column COLLATE utf8_general_ci AS 'column'
如果我們修改查詢此:
...table.column COLLATE latin1_general_ci AS 'column'
它的工作原理。這怎麼可能,MySQL是無處不在的顯示utf8 - 但查詢失敗,只適用於latin1排序規則?
有問題的表是在每次應用程序啓動時生成的,並且明確地設置了默認字符集和默認的分類。
使用完全相同的「代碼」,我們再生成8個表格 - 問題不存在。
任何想法?該envronment是:
- Wildfly 8.1
- MySQL的26年6月5日64
- 休眠4.3.5.Final