Hi everyone,
I am using a MySQL database (V 5.0.27) and JRE 5. All the database tables are InnoDB database with DEFAULT CHARSET=utf8.
I have two columns in two different tables, each defined as VARCHAR(1000). I am trying to copy the contents of one column to the other column via a JDBC connection. When I try to do the insert, I am getting an exception:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'the_column' at row 1
I discovered that the strings that can't be entered are those containing multi-byte unicode characters, such that string.length() <= 1000 but string.getBytes("UTF-8").length() > 1000.
My question is, why can't I insert this data when the tables are defined in exactly the same way? The data in the original table
does have length > 1000 in some cases:
mysql> SELECT LENGTH(the_column), CHAR_LENGTH(the_column) FROM the_table
+--------------------+-------------------------+
| LENGTH(the_column) | CHAR_LENGTH(the_column) |
+--------------------+-------------------------+
| 1003 | 1000 |
+--------------------+-------------------------+
Also, when I copy the data from one table to the other from the sql prompt, it works fine. So it has something to do with going through the JDBC connection, but I don't know what. Any ideas?
Thanks,
Mark