web应用:解决MySQL中文乱码问题

1.查看mysql数据库编码 show variables like '%character%'

 修改见mysql安装配置

(1)修改my.ini配置文件(mysql配置文件)
        #设置字符集,完后重启
        character_set_server = utf8 

(2)修改数据库字符集
        #修改完需要重启mysql数据库
        alter database 数据库名 character set utf8;
        
(3)修改表字符集
        ALTER TABLE  自定义表名 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

2.修改项目数据库文件中配置(根据配置文件类型)

  • 添加useUnicode和characterEncoding并设定为utf-8;注意转义字符和英文问号?

类型一  

修改前

<property name="url" value="jdbc:mysql://localhost:3306/数据库名"/>

修改后

<property name="url" value="jdbc:mysql://localhost:3306/uct?useUnicode=true&amp;characterEncoding=utf-8"/>

类型二

修改前

xxxx.jdbc.url=jdbc:mysql://localhost:3306/数据库名

扫描二维码关注公众号,回复: 12687041 查看本文章

修改后

xxxx.jdbc.url=jdbc:mysql://localhost:8080:3306/数据库名?useUnicode=true&characterEncoding=UTF-8 

猜你喜欢

转载自blog.csdn.net/JinChao94/article/details/108886092
今日推荐