主要解决方向,JAVA与MYSQL中编码要统一。通常采用UTF-8.
这里虽然你在项目中设置了数据库采用UTF-8,但是那里不包括连接方式之类的。
1.查询自身MYSQL编码方式
MySQL默认编码是latin1
mysql> show variables like 'character%';
+--------------------------+--------------------------+
| Variable_name | Value |
+--------------------------+--------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\MySQL\share\charsets\ |
+--------------------------+--------------------------+
2.若项目用UTF8编码,则将MYSQL也改为UTF8编码。通过修改my.ini文件。添加如下几项,再重启MYSQL服务就好。
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。