写连接数据库的URL时指明characterEncoding为GB2312
下面写的是8859_1即ISO-8859-1也是默认的..String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" 

解决方案 »

  1.   

    但是如果要支持国际化
    是不是:
    String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=utf-8"
    然后将MYSQL的数据库设为default-character-set=utf8就好了呢?
      

  2.   

    不行呀,设成user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" 
    后记录集还是乱码呀,后面位大虾请教如何将mysql设为default-character-set=utf8??小弟对mysql不是很熟呀!
      

  3.   

    将mysql设为default-character-set=utf8:在my.ini中添加
    default-character-set=gb2312
    即可
    你还可以试试如下方法:插入数据库时,先把要插入的汉字字符串经过如下tran方法转码:
    public String tran(String code)
        {
            String tmp= new String(code.getBytes(),"ISO-8859-1");
            return tmp;
        }
    把tmp再插入数据库
      

  4.   

    问题是  是你取出来的是乱码.还是你输入的变成乱码...前者是设置MYSQL的字符为GB2312后者是楼上说的..
      

  5.   

    byte[] a=code.getBtyes("ISO8859-1");
    code=new String(a);
      

  6.   

    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;
      }
      

  7.   

    你可以看看我这个得分的例子
    http://expert.csdn.net/Expert/topic/1529/1529097.xml?temp=.9971582我简单总结一下:
    数据库存储最好用8859_1的格式,
    所以存入数据库的时候进行一下编码转换,但我们通常的显示格式为GB2312或GBK,所以取出来的时候再转一次例如:存入数据库时用:
    把数据转成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上通用