A solution to the Chinese encoding of MySQL in hibernate

Source: Internet
Author: User
Tags mysql in mysql insert mysql query

Today in the use of hibernate to MySQL insert data in the garbled problem, the specific performance when I utf-8 in the insertion of the Chinese when the OK, and then use the MySQL Workbench set to Uft-8 to show the data from the MySQL query is also correct, But when I put the data in the code into the database and then query when the query came out is garbled, do not know how to set up, because two utf-8 are no problem, the problem is certainly out in the middle, that is, connect the time. Find the results on the Internet.

All we need to do is set the Hibernate.property or Hibernate.cfg.xml (depending on how you connect to the database) in the file to make it OK.

Originally my connection statement was written:

The code is as follows Copy Code

<property name= "Connection.url" >

Jdbc:mysql://localhost:3306/tablename

</property>

And then I changed it:

The code is as follows Copy Code

<property name= "Connection.url" >

Jdbc:mysql://localhost:3306/tablename?useunicode=true&characterencoding=utf8

</property>

Find or not, the original is to change to this:

  code is as follows copy code

< Property name= "Connection.url"

<![ cdata[

Jdbc:mysql://localhost:3306/tablename?useunicode=true&characterencoding=utf8

]]>

</property>

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.