首页 > 技术文章 > DBC 和 Mybatis连接mysql数据库的时候,设置字符集编码

personsiglewine 2021-06-30 11:12 原文

jdbc连接mysql数据库的时候,设置字符集编码!!!
可以如下配置,mysql可直接在url后面加上字符集设置:


String url = "jdbc:mysql://localhost:3306/exceltest1?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull";

 


Mybatis连接mysql数据库的时候,设置字符集编码!!!
可以如下配置,Mybatis的配置文件中要这样写:(注意要用转义 & 代替&)

<property name="url" value="jdbc:mysql://localhost:3306/exceltest1?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull"/>

 yml文件设置;  connectionInitSqls:set names utf8mb4;

字符集踩坑:

针对表情-4个字节【

推荐阅读