当前位置:网站首页>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四种主流框架!
Unity3D小白学习日记(02):U3D如何连接SQL SERVER数据库(亲测可行!)
PhongAndBelinnPhong光照模型
手把手教你云服务器如何搭建typecho博客网站(包括配置免费SSL证书)
在Ubuntu/Linux环境下使用MySQL:修改数据库sql_mode,可解决“this is incompatible with sql_mode=only_full_group_by”问题
Mysql Workbench用.sql文件将数据导入数据库
IIS发布程序,出现:请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理解决方案
GaN图腾柱无桥 Boost PFC(单相)五-细节处理
安装wcf框架
笔记&代码 | 统计学——基于R(第四版) 第九章一元线性回归
随机推荐
GaN图腾柱无桥 Boost PFC(单相)四(仿真理解)
数学建模美赛题型分类
MySQL5.7安装教程图解
Mysql Workbench导出sql文件出错:Error executing task: ‘ascii‘ codec can‘t decode byte 0xd0 in position 26:
无代码平台邮箱入门教程
MySQL5.7设置MySQL/MariaDB 数据库默认编码为utf8mb4
非线性规划——0-1问题、指派问题例子
整流八--电网不平衡状态下三相PWM整流器的控制策略
笔记&代码 | 统计学——基于R(第四版) 第四章随机变量的概率分布
在Ubuntu/Linux环境下使用MySQL:解决com.mysql.jdbc.PacketTooBigException: Packet for query is too large的问题
pycharm更改默认项目地址的方法
线程与线程池
aspx结尾文件网站的发布过程
如何使用Rancher部署发布自己的web应用
Mysql Workbench uses .sql file to import data into database
Dapr学习(4)之eShopOnDapr部署(Rancher2.63&k3s)
VsCode configures your favorite fonts and backgrounds. Mom no longer worries about my boring code writing.
数学模型建立常用方法
flutter Future的正确用法
光照衰减-Lights