随笔-211  评论-26  文章-8  trackbacks-0

要是页面使用的是UTF-8模式,且文件的编码方式也是UTF-8的。
相信UTF8的优势大家都能知道,如下:
To allow multiple character sets to be sent from the client, the "UTF-8" encoding should be used,
either by configuring "utf8" as the default server character set,
or by configuring the JDBC driver to use "UTF-8" through the characterEncoding property.

另外在添加数据前,必须先执行set names gbk命令,这时才添加数据库数据
后面的编码方式为TYPE=MyISAM default charset=utf8;这时我们每次查看数据库时会都是乱码?号
解决这个问题就是每次查看数据库数据前时,先执行set names gbk.

MYSQL数据库默认语言为瑞典语, 现有一GB2312字符的数据库.
结构OK. 为什么内容是乱码? 不重装数据库有办法解决码?

从MySQL 4.1开始引入的多语言支持确实很棒,而且一些特性已经超过了其他的数据库系统。
不过我在测试过程中发现使用适用于MySQL 4.1之前的PHP语句操作MySQL数据库会造成乱码,
即使是设置过了表字符集也是如此。
我读了一下新的MySQL在线手册中第十章"Character Set Support"后终于找到了解决方法并测试通过。

MySQL 4.1的字符集支持(Character Set Support)有两个方面:字符集(Character set)和排序方式(Collation)。
对于字符集的支持细化到四个层次: 服务器(server),数据库(database),数据表(table)和连接(connection)。

查看系统的字符集和排序方式的设定可以通过下面的两条命令:


mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
7 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-------------------+
| Variable_name | Value |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)



这样,我们在存取数据时,
jdbc:mysql://127.0.0.1/learnjsp?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8";
那里的编码方式也要用utf-8,这时JSP页面上的数据基本就显示正常呢!!!

posted on 2006-10-08 18:04 dragon 阅读(121) 评论(0)  编辑  收藏 所属分类: jsp mysql 乱码解决方案系列