MySQL Chinese encoding solution in Hibernate

Source: Internet
Author: User
You will not only encounter this situation in Hibernate, but also in mainstream php. If your database encoding is different from the page encoding, chinese garbled characters may occur.

You will not only encounter this situation in Hibernate, but also in mainstream php. If your database encoding is different from the page encoding, chinese garbled characters may occur.

Today, we encountered garbled characters when using Hibernate to insert data into MySQL. During the specific performance, I used UTF-8 to print Chinese characters before insertion, then set MySQL Workbench to uft-8 to display the data queried from MySQL is also correct, but when I insert the data in the code and then query it is garbled, I don't know how to set it. Because there is no problem with UTF-8 at both ends, the problem must be in the middle, that is, connect. The search results are found everywhere on the Internet.

We only need to set it in the hibernate. property Or hibernate. cfg. xml (depending on how you connect to the database) file.

My connection statement was originally written as follows:

The Code is as follows:

Jdbc: // localhost: 3306/tablename

Then I changed it:

The Code is as follows:

Jdbc: mysql: // localhost: 3306/tablename? UseUnicode = true & characterEncoding = utf8

I found that it still does not work. I used to change it to this:

The Code is as follows:

</p><p>jdbc:mysql://localhost:3306/tablename?useUnicode=true&characterEncoding=utf8</p><p>

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.