当前位置:网站首页>Use jdbc to handle MySQL's utf8mb4 character set (transfer)
Use jdbc to handle MySQL's utf8mb4 character set (transfer)
2022-08-09 00:32:00 【Daughter controls fake full stack Lao Xu】
Original link address:
http://blog.51cto.com/11931236/2057929
Server Solutions
When consulting the official MySQL documentation, the following official solutions are given to support utf8 to utf8mb4
https://dev.mysql.com/doc/refman/5.7/en/charset-unicode-conversion.html
The above steps are only for server-side configuration.
Additional special handling is required for the client
Because my current project is written in JAVA and uses JDBC to connect to operate the database, the following is the solution for JDBC operation
Configuration before JDBC URL
String url = "jdbc:mysql://HOST:PORT/DATABASE?useUnicode=true&characterEncoding=UTF-8";In the connection configuration, declare the character encoding of UTF-8. In terms of current storage requirements, an error will be reported when storing emoji strings. Even if the server database is set to the utf8mb4 character set type
The client is modified to the following configuration
String url = "jdbc:mysql://HOST:PORT/DATABASE?useUnicode=true&characterEncoding=utf8mb4";An error occurs when the client connects, the character set is not supported
Solutions to the above problems
Change the connection configuration to
String url = "jdbc:mysql://HOST:PORT/DATABASE";At the same time, the database configuration file my.cnf is modified accordingly
[client]default-character-set=utf8mb4[mysql]default-character-set=utf8mb4[mysqld]character-set-client-handshake=FALSEcharacter-set-server=utf8mb4collation-server=utf8mb4_unicode_ciRestart the service MySQL service
The problem is solved here
边栏推荐
猜你喜欢
随机推荐
渐变纹理(光照渐变)
数学模型建立常用方法
LeetCode每日一题(481. Magical String)
备份与恢复
GaN图腾柱无桥 Boost PFC(单相)四(仿真理解)
js实现继承的几种方式
图像超分辨率重建概述
ScreenSpace-ShadowMap(屏幕空间的阴影映射技术)
非科班毕业生,五面阿里:四轮技术面 +HR 一面已拿 offer
aspx结尾文件网站的发布过程
学习思想的内容总结
XShell用命令行打包jar包(详细步骤)
一道dp的三次优化(时间+空间)
注意:服务器
如何选择云服务器与轻量应用服务器?谈谈自己的看法
Phoenix的安装配置以及数据处理(详细步骤)
三角果计数
MVC与MVP的区别
对纹理进行uv坐标偏移
2021江苏省赛









