I have this MySQL table in production that is of charset latin1_swedish_ci ( aka latin1 ) .
Right now, there is this incoming content( String : "\ud55c\ubc24\uc758" ) in a UTF-8 format that needs to be inserted into this TEXT column field called keywords in the table.
When I try to perform the INSERT, I get this error :
Incorrect string value: '\xED\x95\x9C\xEB\xB0\xA4...' for column 'keywords' at row 1
I have tried all kinds of ways in my Java code to try to convert from UTF8 to ISO-8859-1 like this below and I am still getting the same error :
String convertedString = new String(originalString.getBytes("UTF-8"), "ISO-8859-1");
I know there are solutions on StackOverflow that mentions to change the charset of the MySQL table to UTF8 from latin1, and I unfortunately cannot do that because this is a live production MySQL master server and also it has historically been using latin1.
Does anyone have any suggestions to fix this "Incorrect string value" error?
Thanks IS
What you're trying to do simply isn't possible, unless the characters in the utf8 string also happen to have representations in latin1... and latin1 is a tiny single-byte character set (fewer than 256 possible characters, total), so the vast majority of valid utf8 characters have no equivalent latin1 representation.
You can't store any character in the column that the character set of the column doesn't support. It's not a matter of "converting" from one to the other.
If you need unicode, you need at least a utf8 column, and modifying the table is the only alternative. Trying to do otherwise is like trying to store a negative number in an unsigned integer column. Unsigned ints can't be negative -- it's not a matter of conversion.
This would be true of any RDBMS that supports character data types, and is not a limitation specific to MySQL.