Resolves hibernate to MySQL insert Chinese garbled problem (change MySQL character set)

Source: Internet
Author: User
Tags mysql insert

1, first need to modify the MySQL database configuration file My.ini, this file is placed in the MySQL root directory. Look for the Default-character-set property under this file and change its value to UTF8 ( Note: Not utf-8, also note case ), You need to modify the value of all properties of the Default-character-set property to UTF8. Example: default-character-set = UTF8  Tip: There are two default-character-set properties , one under [MySQL] and the other under [mysqld].  2. When you create hibernate database at the same time, you need to display the setting database encoding is UTF8. Example: CREATE DATABASE Daycode default Charset=utf8; 3, to finish these two steps if still not, need to modify Hibernate configuration file Hibernate.cfg.xml, configure the Hibernate.connection.url property in configuration file. Example: <property name= "Hibernate.connection.url" ><! [cdata[jdbc:mysql://localhost:3306/daycode?useunicode=true&characterencoding=utf8]]></property> Note: This string cannot be written as Jdbc:mysql://localhost:3306/daycode?useunicode=true&characterencoding=utf8, or a compile error will occur, and the error message will be & connector changed to;.  after setting these, the garbled problem is solved. --------------------------------The following is the method for setting MySQL characters in Wamp----------------------------------------------------Open My.iniadded under [client]: Default-character-set=utf8[Wampmysqld] under Add:Character_set_server=utf8

init_connect= ' SET NAMES UTF8 '

Save, restart

Resolves hibernate to MySQL insert Chinese garbled problem (change MySQL character set)

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.