Madhura Pande Madhura Pande - 2 months ago 6
MySQL Question

MySQL's UTF-8 character support

I am getting this exception

java.sql.SQLException: Incorrect string value: '\xC2\x99 Adm...' for column
when trying to insert a value in MySQL table. I found that \xC2\x99 maps to U+0099 (or \u0099) which is a 2-Byte character. From documentation, a character with 3 Bytes or less is supported by MySQL's UTF-8. I also read about utfmb4, but since this character is 2 Bytes and still giving this error, so the issue might be something else. Please suggest.

Answer

Looks like you are using the default collation latin1_swedish_ci whereas you should be using utf8_general_ci since you meant to store UTF-8 data in the column. Check MySQL Documentation on Character Sets and Collations in MySQL

You can use an ALTER command to change the collation character set

ALTER TABLE your_table CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;