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 ' * * * *