Solve the Chinese garbled code problem of inserting data from Tomcat to MySQL under Linux

  • 2021-10-13 08:58:49
  • OfStack

1. Problems

The project developed by eclipse on windows runs normally on windows. When deployed to Tencent Cloud, the data inserted into MySQL database is Chinese garbled code

2. Solutions

1. Try 1

Insert Chinese directly on linux using insert statement, normal

2. Try 2

Add useBodyEncodingForURI= "true" in tomcat configuration file server. xml, no

3. Try 3

Add URIEncoding= "UTF-8" in tomcat configuration file server. xml, no

4. Try 4

Because it is an SSM framework project, filters have 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 5

After the jdbc path of the mybatis configuration file, add? characterEncoding=utf-8, success!

The modified jdbc access path is:

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


Related articles: