连接数据库的charset设置成gb2312

解决方案 »

  1.   

    ......
    str=new String(str.getBytes("ISO8859-1"),"gb2312");
    ......
    把上面那句话改成下面这句试试
    str=new String(str.getBytes("gb2312"),"iso-8859-1");
      

  2.   

    存入数据库时用:  
    把数据转成8859_1的格式  
    name=new  String(name.getBytes("gb2312"),"8859_1");  
    content=new  String(content.getBytes("gb2312"),"8859_1");  
     
    insert  into  (name,content)values(?,?).......  
     
    从数据库取的时候用:  
    Connection  con  =  DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1");  
    从数据库取的时候指定编码方式为“8859_1”,  
    然后显示的时候进行转换:  
    name=new  String(name.getBytes("8859_1"),"gb2312");  
    这种方法在MYSQL上通用  
      

  3.   

    public static String toGBK(String str) {
        if (str == null) {
          return null;
        }
        try {
          return new String(str.getBytes("ISO8859_1"), "GBK");
        }
        catch (UnsupportedEncodingException e) {
          e.printStackTrace();
        }
        return null;
      }
      

  4.   

    jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1");  //把useUnicode改为false,就好了。其它地方不用改
      

  5.   

    public class Chinese {
      public String getchinese(String str)
      {
        try
        {
          str=new String(str.getBytes("ISO8859-1"),"GBK");
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
        return str;
      }这样就OK了;
      

  6.   

    好象与web服务器也有关系~~用tomcat应该没问题的,用resin的话如果你是在jsp页面上这样做的话就会乱码,放到servlet里也应该没问题
      

  7.   

    我换了mssql,access都是这个问题
    是jdbc吗
    还是tomcat
      

  8.   

    存入数据库时用:  
    把数据转成8859_1的格式  
    name=new  String(name.getBytes("gb2312"),"8859_1");  
    content=new  String(content.getBytes("gb2312"),"8859_1");  
     
    insert  into  (name,content)values(?,?).......  
     
    从数据库取的时候用:  
    Connection  con  =  DriverManager.getConnection("jdbc:mysql://localhost/gfqqqqpe?user=gfqqqqpe_f&password=aaaaa&useUnicode=true;characterEncoding=8859_1");  
    从数据库取的时候指定编码方式为“8859_1”,  
    然后显示的时候进行转换:  
    name=new  String(name.getBytes("8859_1"),"gb2312");  
    这种方法在MYSQL上通用  如果是resin的话就更好办了!
    只要在jsp页面上加入下面的就可以了!
    <%@ page contentType="text/html; charset=gb2312"%>