views:

75

answers:

0

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.