Write MySQL Chinese data from memory garbled solution

Source: Internet
Author: User

I. Issues

Database code: UTF8

UTF8 COLLATE Utf8_general_ci;

Table code: UTF8

drop table if exists ' test ', create table ' Test ' (' ID ' bigint () not NULL auto_increment COMMENT ' id ', ' name ' varchar (d) Efault ', ' create_time ' timestamp not NULL DEFAULT current_timestamp COMMENT ' creation time ', PRIMARY KEY (' id ')) engine=innodb DEFA ULT charset=UTF8;

JDBC URL:

Url:jdbc:mysql://host:port/dbname

Both the database and database tables already use UTF8 encoding, but they are still garbled when inserting Chinese data.

Two. Causes

when MySQL is connected in JDBC, there is an attribute characterencoding control string encoding in the jdbc URL parameter, which defaults to: AutoDetect. need to be explicitly set to UTF8to resolve the issue.

The MySQL documentation is explained below, see: https://dev.mysql.com/doc/connector-j/5.1/en/ Detailed description of the "Setting Configuration Properties" section in Connector-j-reference-configuration-properties.html.

Three. Workaround

Explicitly set the Characterencoding property to UTF8in the JDBC URL.

url:jdbc:mysql://host:port/dbname?characterencoding=UTF8

Write MySQL Chinese data from memory garbled solution

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.