Hibernate connection MySQL database garbled related problems

Source: Internet
Author: User

1. View MySQL character encoding

>show variables like ' character% '; #执行编码显示

Where character_set_client,character_set_results,character_set_connection three running variables is the key to garbled

2. Modify MySQL encoding format to UTF8

Edit My.ini, (note: Not Utf-8, also pay attention to case)

Locate the client configuration [clients] below to add

# # # Default character set is UTF8

Default-character-set=utf8

When you find [mysqld] Add

# # # Default character set is UTF8

Default-character-set=utf8

# # # (set the MySQL database to use UTF8 encoding to let MySQL database run for UTF8)

init_connect= ' SET NAMES UTF8 '

After modification, restart MySQL, check show variables like ' character% ';

3. 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;

4, to finish these two steps or not, you need to modify Hibernate configuration file Hibernate.cfg.xml, configure the Hibernate.connection.url property in the 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.

Hibernate connection MySQL database garbled related problems

Related Article

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.