从MYSQL中取出的中文字段数据乱码这个问题怎么样才能解决呢?

解决方案 »

  1.   

    /**
     * 字符集转换
     * 
     * @param s
     *            ISO-8859-1字符
     * 
     * @return GBK字符
     */
    public static String toChinese(String s)
    throws UnsupportedEncodingException {
    if (s == null || s.trim().length() == 0) {
    return null;
    } else {
    byte aa[] = s.getBytes("ISO-8859-1");
    String ss = new String(aa, "GBK");
    return ss;
    }
    } /**
     * 字符集转换
     * 
     * @param s
     *            GBK字符
     * 
     * @return ISO-8859-1字符
     */
    public static String toEnglish(String s)
    throws UnsupportedEncodingException {
    if (s == null || s.trim().length() == 0) {
    return null;
    } else {
    byte aa[] = s.getBytes("GBK");
    String ss = new String(aa, "ISO-8859-1");
    return ss;
    }
    }希望对你有用,我联oracle开始也是乱码,通过上面的方法解决了。
      

  2.   

    设置mysql的连接URL,在网上搜索一下,很多的。
      

  3.   

    String str = new String(str.getBytes("ISO-8859-1"),"GBK");