<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 小明 閱讀(1540) 評論(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无码成人网站久久精品大| 亚洲精品高清无码视频| 亚洲成在人线电影天堂色| 最近2019年免费中文字幕高清 | 一级特黄色毛片免费看| 免费国产叼嘿视频大全网站 | 亚洲国产成人精品91久久久| 久久精品国产亚洲沈樵| 亚洲乱妇熟女爽到高潮的片| 热99RE久久精品这里都是精品免费| 亚洲日韩国产精品乱| 三年片免费高清版| 亚洲国语精品自产拍在线观看| 最新亚洲人成无码网站| 亚洲免费福利视频| 亚洲中文字幕一二三四区| 日本免费人成网ww555在线| 亚洲精品高清视频| 最近2019中文字幕mv免费看 | 亚洲中文精品久久久久久不卡| 日本v片免费一区二区三区| 亚洲av无码专区在线播放 | 亚洲人成色777777精品| 免费一级做a爰片性色毛片| 免费看无码特级毛片| 亚洲福利秒拍一区二区| 日本人的色道www免费一区| gogo免费在线观看| 亚洲网站免费观看| 国产一级一片免费播放| 国产午夜成人免费看片无遮挡 | 亚洲无线电影官网| 女人毛片a级大学毛片免费| 国产福利在线观看永久免费| 亚洲精品私拍国产福利在线| 国产极品美女高潮抽搐免费网站| 亚洲综合激情五月色一区| 午夜亚洲国产成人不卡在线| 亚洲成a∧人片在线观看无码|