当前位置:网站首页>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_ci
Restart the service MySQL service
The problem is solved here
边栏推荐
猜你喜欢
JSON基础,传递JSON数据,介绍jackson、gson、fastjson、json-lib四种主流框架!
利用Ehcache分布式缓存,轻松打造商业级高并发、高性能API接口!
灰色预测模型
Several ways to implement inheritance in js
flutter loading、Progress进度条
全新Swagger3.0教程,OAS3快速配置指南,实现API接口文档自动化!
如何使用Rancher部署发布自己的web应用
Phoenix的安装配置以及数据处理(详细步骤)
Mysql Workbench用.sql文件将数据导入数据库
笔记&代码 | 统计学——基于R(第四版) 第二章数据可视化
随机推荐
Mysql Workbench uses .sql file to import data into database
解决8080端口被占用问题
笔记&代码 | 统计学——基于R(第四版) 第四章随机变量的概率分布
云服务器可以用来做什么?有什么用途?
矩阵乘法总结
逐片元-兰伯特光照模型
统一身份管理平台IAM单点登录流程及第三方接口设计方案
js 实现数字跳动
最优化问题——线性规划模型
对于js中apply和call的区别和用法
神经网络基本原理
2020-10-17
如何使用Rancher部署发布自己的web应用
对纹理进行uv坐标偏移
整流十二 -有效值、平均值、瞬时值、幅值的关系以及相关方法
Shader实现帧动画-FrameAnimation
控件限制总结
win10出现次磁盘占用率百分之百的情况
如何选择云服务器与轻量应用服务器?谈谈自己的看法
为什么软件开发方法论让你觉得糟糕?