Solve the problem of inserting garbled characters in MySQL

Source: Internet
Author: User
Tags mysql in

Today when using Java to write to the database, we find that the INSERT statement and UPDATE statement after the execution, the database in Chinese display is "?? , after a review, the key question is whether the encoding format is uniform.

When creating a table, the format of each keyword is set to uniform, where I set the UTF8

  

Then you will find that in the database, the execution of SQL statements, will not be garbled, but in the use of Java calls, will be garbled, in fact, the reason is that, in connection with the database, we need to define the encoding format, we see the code is understood, when the encoding format is unified for UTF8 time, There will be no garbled characters.

  

1 class.forname ("Com.mysql.jdbc.Driver"2             //mydatabase is the database name, _test is the table name. There are three fields in the _test table: ID name author publish3             con = drivermanager.getconnection ("Jdbc:mysql://localhost : 3306/mydatabase?characterencoding=utf8 "," root "," 123456 ");

Where the encoding format is set to {? Characterencoding=utf8} this sentence.

(Another is the import data when the garbled phenomenon occurred, the solution is as follows:)

MySQL in the default database encoding set is not utf-8, so in the import data table when there is a Chinese error, this time to create a new own database, choose the encoding format for UTF8, sorting set is selected Utf8-unicode, and then import the data can be.

Reference: http://www.cnblogs.com/time-is-life/p/5901868.html

Modify the default character set: Http://www.cnblogs.com/xingyunblog/p/3836299.html

(for reference study only)

Solve the problem of inserting garbled characters in MySQL

Related Article

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.