开发者

Error with two byte UTF-8 character in UPDATE statement for MySQL database

An update-statement seems to work only with one or three byte long UTF-8 characters.

My test code

def sql = sql.newInstance('jdbc:mysql://.../...?useUnicode=true&characterEncoding=UTF-8',
            '...', '...', 'com.mysql.jdbc.Driver')
String value = 'β'
sql.execute('UPDATE Kldb_SynonymVersion SET synonyms=? WHERE id=11940', [value])
开发者_开发百科

fails with

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'synonyms' at row 1

in com.mysql.jdbc.MysqlIO.checkErrorPacket.

It works with value="a" or value = '€'.

I am using

java 1.6.0_20

mysql 5.0.26

mysql-connector 5.1.13

The character-set of the table is set to utf8.

I know that I can disable the truncation, but than I only avoid the exception and get an invalid character ('?') in the database.


Are you sure that column encoding of MySQL column is UTF-8.

MySQL driver is able to write unicode characters to ASCII columns, and even read them correctly, so the problem can be unnotified for long time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜