使用客服端工具如navicat,自带的命令行工具是能够插入中文记录的。但是使用jdbc就不行了。
开始是使用mybatis出现了这个问题。一度怀疑是mybatis的问题,最后直接写jdbc连接插入记录
中文也乱码。
下面贴出mysql的一些变量。
发现character_set_server为拉丁字符。其他的都正常。
使用jdbc为什么就乱码了呢?求大神解答。
黄舟2017-04-17 14:02:21
Try this: jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=gbk
Explanation: http://www.cnblogs.com/xuefuwu/archive/2012/05/06/2486577.html
巴扎黑2017-04-17 14:02:21
What character set does your table use? show create table TABLE_NAME, and what encoding do you use for java? gbk, gb2313?
迷茫2017-04-17 14:02:21
Maybe the encoding of the jdbc connection is wrong and needs to be specified as utf-8