Mysql latin1 is not equal to the standard latin1 (iso-8859-1) and cp1252, 0x80-0x9f characters more than the iso-8859-1, than cp1252 0x81, 0x8d, 0x8f, 0x90, 0x9d has a total of five characters.
Http://dev.mysql.com/doc/refman/5.0/en/charset-we-sets.html
Latin1 is the default character set. mySQL's latin1 is the same as the Windows cp1252 character set. this means it is the same as the official ISO 8859-1 or IANA (Internet Assigned Numbers Authority) latin1, could t that IANA latin1 treats the code points between 0x80 and 0x9f as "undefined," whereas cp1252, and therefore MySQL's latin1, assign characters for those positions. for example, 0x80 is the Euro sign. for the "undefined" entries in cp1252, MySQL translates 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d.
In Java, garbled characters may occur if standard iso-8859-1 or cp1252 decoding is used.
S. getBytes ("iso-8859-1") or s. getBytes ("cp1252 ");
I wrote a piece of code to solve this problem.
Private String convertCharset (String s ){
If (s! = Null ){
Try {
Int length = s. length ();
Byte [] buffer = new byte [length];
// 0x81 to Unicode 0x0081, 0x8d to 0x008d, 0x8f to 0x008f, 0x90 to 0x0090, and 0x9d to 0x009d.
For (int I = 0; I <length; ++ I ){
Char c = s. charAt (I );
If (c = 0 x0 0081 ){
Buffer [I] = (byte) 0x81;
}
Else if (c = 0x008d ){
Buffer [I] = (byte) 0x8d;
}
Else if (c = 0x008f ){
Buffer [I] = (byte) 0x8f;
}
Else if (c = 0x0090 ){
Buffer [I] = (byte) 0x90;
}
Else if (c = 0x009d ){
Buffer [I] = (byte) 0x9d;
}
Else {
Buffer [I] = Character. toString (c). getBytes ("cp1252") [0];
}
}
String result = new String (buffer, "UTF-8 ");
Return result;
} Catch (UnsupportedEncodingException e ){
Logger. error ("charset convert error", e );
}
}
Return null;
}
From James's Thoughts