Hibernate MySQL write Chinese garbled solution

Source: Internet
Author: User

Start Hibernate project, automatically create a table, after inserting data found in the data written in the table is garbled in Chinese. The following methods are resolved:

  1. The character set for the modified database is UTF-8, which can be changed by right-clicking the properties of the database to be modified by MySQL client software.

  2. Modify the client default character set to UTF8. Under Windows in the MySQL installation directory (My Computer operating system is Windows 7 64, the default installation path is found under: C:\Program Files (x86) \mysql\mysql Server 5.0) My.ini, Change the default-character-set=latin1 to Default-character-set=utf8, and then restart the MySQL service to change the database default character set to UTF8.

  3. In the project's hibernate configuration file, modify the value of the property named "Hibernate.connection.url" to Hibernate.cfg.xml: jdbc:mysql://localhost:3306/ Tdm?useunicode=true&characterencoding=utf-8, where TDM is the name of the database.

  4. Then start the project, execute the code, the inserted Chinese will not be garbled.

Hibernate MySQL write Chinese garbled solution

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.