Tag Archives: data truncation data too long for column

Data truncation: Data too long for column ‘****’

Explain the function of static keyword and final keyword in Java in detail>>>

Today, when writing the code, I found that Chinese was stored in MySQL garbled

Hibernate for my data persistence framework. First of all, I confirm that the Chinese data transferred from JSP page to the background is not garbled, so I am sure that there is something wrong with the storage of Chinese data. Looking up information on the Internet, many people say that you can add the following in the configuration file of Hibernate:

<propertyname="connection.characterEncoding">utf-8</property>

After adding this sentence, I still can’t. Keep looking up the information. Then, it suddenly occurred to me that I didn’t specify the code when I built the database, and the data used the default code of MySQL (and the default code of MySQL was determined during installation). So I delete the existing database (small project, it doesn’t matter to delete it), rebuild the database, and specify the code when building the database

createdatabase`db_photodisplay`defaultcharactersetutf8collateutf8_general_ci;

After the database is built, the table is rebuilt. New errors occurred in the operation of the project

Data truncation: Data too long for column ‘rolename’ at row 1

Continue with the mistake of Baidu. Someone on Baidu said that it would be better to add engine = InnoDB default character set = utf8 when creating tables

So I deleted the table and added engine = InnoDB default character set = utf8 when creating the table

CREATETABLE`role_info`(
`id`bigint(20)NOTNULL,
`rolename`varchar(50)NOTNULL,
PRIMARYKEY(`id`)
)engine=innodbdefaultcharacterset=utf8

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

[Solved] The length of the data truncation done by springboothinesdata for the column.

Questions

According to the error report, the field defined in the database is too short to store new data

Solution

  @Column(length = 3000)
  private String cellExcel;

Manually define the length of the field, but it will not take effect on the existing table, so you still need to use SQL statements to manually modify the length of the table field, that is:

ALTER TABLE mydb.form_template_field MODIFY COLUMN cell_excel VARCHAR(3000);