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