你试试这样看行不行?
String dburl="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GB2312";
或者你从数据库读出的时候作个转换
String str=new String(str.getBytes("ISO-8859-1"),"GB2312");
String dburl="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=GB2312";
或者你从数据库读出的时候作个转换
String str=new String(str.getBytes("ISO-8859-1"),"GB2312");
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)
我昨天找的时候,看到的帖子也是象二楼的说法String str=new String(str.getBytes( "ISO-8859-1 "), "GB2312 ");
请指点清楚一点,这句话是加在哪里?加在页面上吗?getBytes是java的方法吧,我用的是php该怎么实现?
下面是我的一个例子:
//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();
}
因为如果是这种办法的话,岂不是每次从库里读中文信息都要先执行一下这个语句,这样是不是有点麻烦啊
有可以彻底解决这个问题的办法吗,就是不用mysql_query('set names "utf8"');也不会出现"??"