在向数据库中插入数据的时候,中文的时候要进行字符转换!在插入中文的地方调用!
/**** 字符集的转换函数 ****/
        // added by baiqing 2003.02.18
        public static String charConvert(String strSource){
            if (strSource == null){
                return "";
            }
            else{
                try{
                  //return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
                  String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
                  System.out.println(str);
                  return str;
                }
                catch (Exception ex){
                  System.out.println(ex.toString());
                  return "";
                }
            }
        }
 

解决方案 »

  1.   

    在向数据库中插入数据的时候,中文的时候要进行字符转换!在插入中文的地方调用!
    /**** 字符集的转换函数 ****/
            // added by baiqing 2003.02.18
            public static String charConvert(String strSource){
                if (strSource == null){
                    return "";
                }
                else{
                    try{
                      //return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
                      String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
                      System.out.println(str);
                      return str;
                    }
                    catch (Exception ex){
                      System.out.println(ex.toString());
                      return "";
                    }
                }
            }
     
      

  2.   

    up一下
    顺便也提个问题,如果jsp中 charset=gb2312,还需要这种转换吗?我没有测试过:)
      

  3.   

    转成GB2312String address = "";
    try {
      address = new String(str.getBytes("iso-8859-1"), "GB2312");
    }
      catch (UnsupportedEncodingException ex3) {
    }
      

  4.   

    再转会乱码的------------------------------
    up一下
    顺便也提个问题,如果jsp中 charset=gb2312,还需要这种转换吗?我没有测试过:)
      

  5.   

    在JSP中:如果你在数据库中存的是中文,那取出来是就不需要转换。。
    否则,就要用String str= new String(str.getBytes("iso-8859-1"), "GB2312");进行一下转换一下。
      

  6.   

    gb2312还不够,你应该用Gbk重新编码