Solve the garbled code when javaweb inserts Chinese data into the database
Tips before viewing:
The Eclipse version used in this article is Photon Release (4.8.0), the JDK version is 1.7.0_80, the Tomcat version is 8.5.34, and the MySQL version is 5.7.26.
This article is a solution to the problem I encountered, for reference only.
After installing MySQL 5.7.26 locally, I built a web project by myself. When I inserted Chinese data, I found that ??? garbled characters appeared. The
project code was checked as shown in the figure below. After the database code, it was found that they were all utf-8. I was puzzled. Finally, when I checked the database configuration file datasource.properties, I found that the characterEncoding=UTF-8
configuration was missing. After adding the database, it was normal to insert Chinese data.