Java inserting Chinese characters into MySQL is garbled

Source: Internet
Author: User

A new MySQL database table was created yesterday, and when inserting Chinese characters into Java, it was found that the insertion result in the database was garbled. The actual character set does not meet the problem.

There are a number of solutions to this problem, such as the Java and MySQL garbled problem in this article but I recommend that you delete the table by deleting the new table and setting the default character set to UTF-8 when the table is built, so that you can avoid any problems later.

You can view the encoding format of the table by using the statement Show CREATE TABLE table_name. For example mine is:

CREATE TABLE' blog ' (' title 'varchar( -) not NULL DEFAULT "', ' username 'varchar( -)DEFAULT NULL, ' content 'varchar( the)DEFAULT NULL, ' createtime ' dateDEFAULT NULL,  PRIMARY KEY(' title ')) ENGINE=InnoDBDEFAULTCHARSET=Utf8

This is the modified statement, the initial view is that the encoding format is latin1, the Build Table tool uses Navicat, the default is to build the table is Latin1, you can select the "Options" tab in the table, select UTF-8 in the character set, such as:

Java inserting Chinese characters into MySQL is garbled

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.