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

VMwarea virtual machine installation win7 operating system tutorial diagram

The installation process of VMwarea will not be d...

Should nullable fields in MySQL be set to NULL or NOT NULL?

People who often use MySQL may encounter the foll...

Detailed explanation of four solutions to floating problems in CSS layout

1. Cause: The effect after the subbox is set to f...

Implementation of CSS heart-shaped loading animation source code

Without further ado, let me show you the code. Th...

Introduction to MySQL MHA operation status monitoring

Table of contents 1. Project Description 1.1 Back...

How to install openssh from source code in centos 7

Environment: CentOS 7.1.1503 Minimum Installation...

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...

CentOS 7 cannot access the Internet after modifying the network card

Ping www.baidu.com unknown domain name Modify the...

JavaScript to achieve simple image switching

This article shares the specific code for JavaScr...

How to get datetime data in mysql, followed by .0

The data type of MySQL is datetime. The data stor...

Mobile front-end adaptation solution (summary)

I searched online and found that many interviews ...

javascript:void(0) meaning and usage examples

Introduction to void keyword First of all, the vo...

UCenter Home site adds statistics code

UCenter Home is an SNS website building system rel...

Summary of common tool functions necessary for front-end development

1. Time formatting and other methods It is recomm...

A brief discussion on the lock range of MySQL next-key lock

Preface One day, I was suddenly asked about MySQL...