解决java和mysql连接时汉字出现乱码的问题

1..java文件中数据库url后面要加上useUnicode=true&characterEncoding=xxx(文字编码。汉字编码一般用GBK和GB2312),如jdbc:mysql://localhost:3306/exp4?useUnicode=true&characterEncoding=GBK

2.在mySQL中新建数据库时,要指定数据库编码

SET character_set_client = gbk;
SET character_set_connection = gbk;
SET character_set_database = gbk;
SET character_set_results = gbk;
SET character_set_server = gbk;

SET collation_connection = gbk_bin;
SET collation_database = gbk_bin;
SET collation_server = gbk_bin;

你可能感兴趣的:(解决java和mysql连接时汉字出现乱码的问题)