<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;
        }
    主站蜘蛛池模板: 女人让男人免费桶爽30分钟| 亚洲日韩v无码中文字幕| 免费一级特黄特色大片| 亚洲综合另类小说色区色噜噜| 永久免费AV无码网站国产| 亚洲伊人久久精品| 亚洲v国产v天堂a无码久久| 99精品免费观看| 国产精品亚洲小说专区| 亚洲成人免费在线| 国产无遮挡又黄又爽免费视频| 国产啪精品视频网站免费尤物| 国产亚洲精品成人AA片| 亚洲av无码国产精品夜色午夜| 日本大片在线看黄a∨免费| 99精品一区二区免费视频| 日韩少妇内射免费播放| 国产精品亚洲综合五月天| 综合亚洲伊人午夜网| 在线免费观看污网站| 人人揉揉香蕉大免费不卡| 国产亚洲视频在线观看网址| 亚洲黄色网址大全| 亚洲最大av无码网址| 成人免费毛片观看| 最近免费中文字幕高清大全 | 嫩草视频在线免费观看| 中文字幕永久免费视频| 亚洲av色香蕉一区二区三区| 91在线亚洲精品专区| 国产gv天堂亚洲国产gv刚刚碰| 日韩在线免费电影| 青青久在线视频免费观看| 日韩人妻一区二区三区免费| 成人A毛片免费观看网站| 国产亚洲精品AAAA片APP| 日韩亚洲人成在线| 亚洲精品国产情侣av在线| 亚洲综合无码精品一区二区三区| 亚洲免费视频在线观看| 亚洲国产人成在线观看69网站|