<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小明思考

    Just a software engineer
    posts - 124, comments - 36, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    詭異的mysql latin1編碼

    Posted on 2012-02-24 14:54 小明 閱讀(1532) 評論(0)  編輯  收藏 所屬分類: 開發日志

    Mysql 的latin1 不等于標準的latin1(iso-8859-1) 和cp1252,比iso-8859-1多了0x80-0x9f字符,比cp1252多了0x81,0x8d,0x8f,0x90,0x9d 一共5個字符。

     

    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, except 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.

    這樣在Java中,如果使用標準的iso-8859-1或者cp1252解碼可能出現亂碼。
    s.getBytes("iso-8859-1") 或者 s.getBytes("cp1252");

    寫了一段代碼來解決這個問題
    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==0x0081){
                            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;
        }
    主站蜘蛛池模板: 亚洲AV无码专区在线亚| 亚洲欧洲精品无码AV| 亚洲综合一区二区三区四区五区| 100部毛片免费全部播放完整| 亚洲av福利无码无一区二区| 久久午夜夜伦鲁鲁片无码免费| 久久国产精品亚洲综合| 久久久高清日本道免费观看| 亚洲欧洲在线观看| 最近免费mv在线电影| 亚洲an日韩专区在线| 国产小视频免费观看| 高清免费久久午夜精品| 国产亚洲精品激情都市| 在线观看免费无码专区| 久久国产亚洲高清观看| 毛片A级毛片免费播放| 国产99久久亚洲综合精品 | 免费阿v网站在线观看g| 久久亚洲国产成人影院| 免费又黄又爽的视频| 两个人看的www免费高清| 中文字幕在线观看亚洲| 四虎www成人影院免费观看| 免费国产黄网站在线看| 亚洲国产一二三精品无码| 在线观看www日本免费网站| 亚洲精华国产精华精华液网站| 亚洲日韩国产一区二区三区| 久久久精品免费国产四虎| 亚洲午夜电影在线观看| 免费一级做a爰片久久毛片潮喷| 一区二区在线视频免费观看| 日本久久久久亚洲中字幕| 日本媚薬痉挛在线观看免费| 久久久久久国产a免费观看不卡| 在线免费观看亚洲| 免费观看国产精品| 最近中文字幕免费完整| 羞羞视频免费观看| 亚洲精品影院久久久久久|