Data Truncation:data too long for column ' * * * *

Source: Internet
Author: User

Writing code today found that Chinese stored in MySQL garbled.

My data persistence framework uses Hibernate. First I confirm that the JSP page passed in the background of Chinese data is not garbled, so I am sure that the Chinese data in the storage of a problem. Online access to information, many people say can be added in Hibernate configuration file:

<property name= "Connection.characterencoding" >utf-8</property>

It is still not good to add this sentence. Continue to check the information ..... Then it occurred to me that maybe I didn't specify the code when I built the database, and the data used the default encoding for MySQL (and MySQL's default encoding was determined at the time of installation). So I will delete the existing database (small project, delete does not matter), rebuild the library, build the library when you specify the encoding

Create database ' Db_photodisplay ' default character set UTF8 collate utf8_general_ci;

After building the library, rebuild the table. Running the project, a new error has occurred:

Data Truncation:data too long for column ' RoleName ' at row 1

Continue Baidu this mistake, Baidu on someone said, build the table add engine=innodb default character Set=utf8 is good.

So I deleted the table and added engine=innodb default character Set=utf8 when I built the table.

CREATE TABLE ' role_info ' (' ID ' bigint () not NULL, ' rolename ' varchar () ' is not NULL, PRIMARY KEY (' id ')) Engine=innodb D Efault character Set=utf8

Re-run the project, found that Chinese data successfully stored in the database, no garbled.

Data Truncation:data too long for column ' * * * *

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.