<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;
        }
    主站蜘蛛池模板: 亚洲乱码卡一卡二卡三| 亚洲精品国产摄像头| 足恋玩丝袜脚视频免费网站| 亚洲免费观看网站| 小小影视日本动漫观看免费| 一级大黄美女免费播放| 亚洲毛片免费视频| 亚洲AⅤ无码一区二区三区在线| 精品国产麻豆免费人成网站| 亚洲jjzzjjzz在线播放| 亚洲日韩中文在线精品第一| 1000部啪啪未满十八勿入免费| 亚洲AV无码专区亚洲AV桃| 久久精品九九亚洲精品天堂| 一区二区无码免费视频网站| 一区二区视频免费观看| 亚洲欧洲国产成人精品| 亚洲不卡AV影片在线播放| 日本免费一区二区三区| 在线精品自拍亚洲第一区| 日韩精品一区二区亚洲AV观看 | 日韩免费高清视频网站| 一区二区三区无码视频免费福利| 亚洲中文字幕无码一去台湾| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 国产亚洲免费的视频看| 亚洲成a人片在线观看中文动漫 | 亚洲精品国产电影| 手机在线看永久av片免费| 美女视频黄视大全视频免费的| 亚洲人成电影在线天堂| 国产成人免费ā片在线观看| 日韩午夜理论免费TV影院| 亚洲av无码有乱码在线观看| 亚洲男女一区二区三区| 亚洲AV永久无码精品水牛影视| 日本一道在线日本一道高清不卡免费| 日韩插啊免费视频在线观看| 中国国语毛片免费观看视频| 在线观看亚洲网站| 亚洲成av人片在www鸭子|