How to solve the problem of Incorrect string value when saving Chinese characters to mysql in java

Source: Internet
Author: User
Tags mysql tutorial

Today, I wrote a group buying website trainer who used the S2SH big integration. It was a bit exciting, but there were a lot of troubles. After all, what I did for the first time? This log is about a big acquaintance, incorrect string value: 'xe6x9bxb9xe5x86xac... 'for column 'realname' at row 1, hey, I 've seen a lot before.

The following error occurs when you enter Chinese characters.

 

I understand that this error occurs. In all likelihood, there is a problem with the encoding of the database tutorial. I was too lazy to study it before. I was lucky to write a Syso in the background to check whether the console output was garbled and the result showed that it was normal, if there are no garbled characters, it is definitely a database encoding problem.

Mysql tutorial database I used, Version 5.1.

Use show variables like 'character % 'to view the database encoding. latin1 is expected.

If the project is being tested and the data is not important, the solution is to use alert database tuanplus character set utf8 to change the encoding format of the database, and then create a new table (in Hibernate, specify hibernate. hbm2ddl. auto = create, re-deploy the project, hibernate will automatically re-create the table), view the database code at this time, hey, it's utf8. Exception relief.

If the data in the project is important data, there is still a solution.

To use alter table address convert to character set utf8 to convert the data table that needs to be inserted into Chinese characters, encode it as utf8 (in this example, the data table is address ):

Back up data in advance to avoid exceptions

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.