你试试这样看行不行?
String dburl="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GB2312";
或者你从数据库读出的时候作个转换
String str=new String(str.getBytes("ISO-8859-1"),"GB2312");

解决方案 »

  1.   

    还有你要检查一下mysql数据库字符集的设置有没有弄好,我用的字符集是utf8,下面是我的设置:
    mysql> show variables like "%char%";
    +--------------------------+----------------------------------------------------
    -----+
    | Variable_name            | Value
         |
    +--------------------------+----------------------------------------------------
    -----+
    | character_set_client     | utf8
         |
    | character_set_connection | utf8
         |
    | character_set_database   | utf8
         |
    | character_set_results    | utf8
         |
    | character_set_server     | utf8
         |
    | character_set_system     | utf8
         |
    | character_sets_dir       | C:\Program Files\MySQL\MySQL Server 5.0\share\chars
    ets\ |
    +--------------------------+----------------------------------------------------
    -----+
    7 rows in set (0.14 sec)mysql> show variables like"%coll%";
    +----------------------+-----------------+
    | Variable_name        | Value           |
    +----------------------+-----------------+
    | collation_connection | utf8_general_ci |
    | collation_database   | utf8_general_ci |
    | collation_server     | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.00 sec)
      

  2.   

    TO hy2003fly() :
    我昨天找的时候,看到的帖子也是象二楼的说法String  str=new  String(str.getBytes(  "ISO-8859-1  "),  "GB2312  "); 
    请指点清楚一点,这句话是加在哪里?加在页面上吗?getBytes是java的方法吧,我用的是php该怎么实现?
      

  3.   

    php的话要在query()之前加多一句mysql_query('set names "charset"');
    下面是我的一个例子:
      //execute query
      mysql_query('set names "utf8"');//如果没有这一句就会出现乱码
      $Query="select * from books";
      //$Query="select user,host from user order by 1,2";
      if(!($dbResult=mysql_query($Query,$dblink)))
      {
          print("Could not execute query!<br>\n");
      print(mysql_errno().":".mysql_error()."<br>\n");
      exit();
      }
      

  4.   

    顺便再问一下,除了用mysql_query('set names "utf8"');这样的办法,还有更好的吗?
    因为如果是这种办法的话,岂不是每次从库里读中文信息都要先执行一下这个语句,这样是不是有点麻烦啊
    有可以彻底解决这个问题的办法吗,就是不用mysql_query('set names "utf8"');也不会出现"??"