JDBC插入中文到MySQL显示为问号

158 阅读1分钟

解决思路

1、查看字符集

执行如下查询语句,查看字符集;mysql数据库中的编码方式是否一致,编码为UTF-8

 

show variables like '%character%';

 

2、在链接数据时,有没有在url里面加上 characterEncoding=utf8,如下

 

jdbc:mysql://localhost:3306/demo?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true