今天测试jfinal 框架就写了个 小web项目 但是出现了问题 后台接收的数据时中文但是存到数据库却是乱码!
Method : add
Parameter : sex=a password1=aaa username=啊 flag=doAdd button=数据提交 address=21 tel=1 age=12 password=aaa auth=0
--------------------------------------------------------------------------------
确定是数据库的问题
使用 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_set_system 是utf-8编码
都是 latin1
直接通过命令进行修改
set character_set_client=utf8;
set character_set_connection=utf8;
set character_set_database=utf8;
set character_set_results=utf8;
set character_set_server=utf8;
修改完了之后再查询
show variables like 'character%‘
+--------------------------+--------+
| Variable_name | Value |
+--------------------------+--------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
+--------------------------+--------+
'
如果项目中的数据是重要数据的话,还是有解决办法滴。
使用 alter table table_name convert to character set utf8 转换需要插入汉字的数据表编码为utf8即可: