终极解决MySql乱码

MySql乱码问题


        你是否和我遇到了同样的问题,因为MySql数据库中读取中文信息总是乱码而纠结?下面教你一套终极方法来解决它!

1、将整个工程的字符集设置成“UTF-8”:右击整个工程 ——>快捷菜单“property”——>在Resource中设置“UTF-8”;

2、将JDBC中的URL也设置成“UTF-8”:“ url= "jdbc:mysql://localhost:3306/HouseManage?useUnicode=true&characterEncoding=utf8";”

3、将MySql安装目录下的“my.ini”用记事本打开,

在[client]下添加default-character-set=utf8

在[mysqld]下添加default-character-set=utf8

在“命令提示符下”(win键+R,输入"cmd"命令打开),重新启动MySql 

net stop mysql
net start mysql


4、创建数据库表时要加一个字符集设置


例如:

引用
create table student_info
(
   id                   int not null auto_increment,
   dentityId            varchar(20) not null,
   name                 varchar(20) not null,
   sex                  varchar(4) not null,
   term                 varchar(20) not null,
   major                varchar(50) not null,
   college              varchar(50) not null,
   state                int not null default 0,
   primary key (id)
) type=MyISAM default charset utf8;


5、注意,请不要直接要数据库中insert数据,不然还是乱码,而要通过java代码实例来对数据库insert;


好啦!Congratulations!成功啦!



猜你喜欢

转载自sean2012.iteye.com/blog/1876020