About the "Warn:sql error:1366, sqlstate:hy000" error solution

Source: Internet
Author: User



When importing data to MySQL, the following error message appears:



Org.hibernate.engine.jdbc.spi.SqlExceptionHelper logexceptions
Error:incorrect string value: ' \xe5\x95\x8a\xe5\xae\x9e ... ' for column ' Titel ' at row 1




Reason
This is because the MySQL database character set is UTF8, and the imported data contains non-UTF8 encoded characters (especially Chinese or other non-English characters), so this error occurs.

Solution
Method 1:
Convert the data you want to import into UTF8 encoding before importing. (if it is txt, CSV and other text data, you can open with Notepad, and then save as UTF-8 encoded text)

Method 2:
1) Modify the data table character set in MySQL to import data, for example: Change to Chinese GBK character set



Modify the code (MySQL console):
mysql> ALTER TABLE content Modify author varchar (in) character set GBK;
Note: All columns in the data table must be processed individually. Then re-import the data to succeed!

2) the page needs to be declared with GBK or GB2312 code, and the page needs to be transcoded, for example:
String content1 = new String (Request.getparameter ("Content1"). GetBytes ("iso-8859-1"));
Page reads do not require transcoding, and writing requires transcoding.

Method 3:
To modify the encoding of the entire database:
mysql> ALTER DATABASE TestDB character set GBK;



About the "Warn:sql error:1366, sqlstate:hy000" error solution


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.