Mybatis + Mysql inserting data when the Chinese garbled problem

Source: Internet
Author: User

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&amp;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 ' &amp; ' here.

Mybatis + Mysql inserting data when the Chinese garbled problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.