Recently with friends to build a project, with the Spring+mybatis+mysql.
I met a mybatis today. When inserting data into MySQL, Chinese is displayed as '??? ' Problem, take out the next.
For the database operation in the Chinese garbled, there are generally two kinds of situations:
- The database itself is set
- When connecting to a database, the encoding settings for JDBC
For the first case, you can view your own MySQL settings:
Show variables like '%character% '
Display the specified encoding to resolve the issue:
<!--- <bean id= "DataSource" class= " Org.springframework.jdbc.datasource.DriverManagerDataSource "> <property name=" Driverclassname "value=" Com.mysql.jdbc.Driver "/> <property name=" url "value=" jdbc:mysql://127.0.0.1:3306/uct? useunicode= True&characterencoding=utf-8"/> <property name=" username "value=" root "/> < Property name= "Password" value= "/> </bean>
You can see that the Useunicode and characterencoding values are added after the URL of the connection, set to Utf-8.
One thing to note here is that you need to escape the ' & ' symbol in the XML configuration file, so write ' & ' here.
Mybatis + Mysql inserting data when the Chinese garbled problem