Solve the problem of Chinese garbled characters when inserting data into MySQL by Tomcat under Linux

Solve the problem of Chinese garbled characters when inserting data into MySQL by Tomcat under Linux

1. Problem

The project developed using Eclipse on Windows runs fine on Windows, but when deployed to Tencent Cloud, the data inserted into the MySQL database is garbled Chinese characters

2. Solution

1. Try one

Use the insert statement directly on Linux to insert Chinese characters.

2. Attempt 2

Add useBodyEncodingForURI="true" to the tomcat configuration file server.xml, it doesn't work

3. Attempt 3

Adding URIEncoding="UTF-8" to the tomcat configuration file server.xml does not work

4. Attempt 4

Since it is an SSM framework project, a filter has been added in web.xml

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

no

5. Try five

Add ?characterEncoding=utf-8 after the jdbc path in the mybatis configuration file, success!

The modified jdbc access path is:

jdbc:mysql://localhost:3306/daad?characterEncoding=utf-8

You may also be interested in:
  • Solution to the garbled code problem in MySQL 5.x
  • Solution to the Chinese garbled code problem in the decompressed version of MYSQL
  • How to solve the problem of Chinese garbled characters when using MySQL to obtain database data
  • Example solution for writing garbled Chinese characters into MySQL in PHP
  • MySQL character set garbled characters and solutions
  • Solution to MySQL garbled code problem under Linux
  • How to deal with garbled characters in Mysql database
  • How to solve the problem of Chinese garbled characters when inserting table data into MySQL
  • Summary of handling JDBC connection mysql garbled code exception problem
  • How to solve the DOS window garbled problem in MySQL

<<:  How to turn local variables into global variables in JavaScript

>>:  How to use nginx as a load balancer for mysql

Recommend

Example of adding music video to HTML page

1. Video tag Supports automatic playback in Firef...

Overview of MySQL Statistics

MySQL executes SQL through the process of SQL par...

When modifying a record in MySQL, the update operation field = field + string

In some scenarios, we need to modify our varchar ...

How to set the border of a web page table

<br />Previously, we learned how to set cell...

Implementation of textarea adaptive height solution in Vue

Table of contents Hidden Problems Solution to ada...

CSS multi-column layout solution

1. Fixed width + adaptive Expected effect: fixed ...

Detailed steps for adding hosts you need to monitor in zabbix

Add monitoring host Host 192.168.179.104 is added...

How to use Docker to build enterprise-level custom images

Preface Before leaving get off work, the author r...

CSS to achieve Tik Tok subscription button animation effect

I was watching Tik Tok some time ago and thought ...

Win10 + Ubuntu 16.04 dual system perfect installation tutorial [detailed]

Be sure to remember to back up your data, it is p...

Docker compose custom network to achieve fixed container IP address

Due to the default bridge network, the IP address...

Some understanding of absolute and relative positioning of page elements

From today on, I will regularly organize some smal...