Java inserting Chinese into database garbled

Source: Internet
Author: User

Reference http://www.cnblogs.com/jack204/archive/2012/09/11/2680106.html

The main solution direction, Java and MySQL coding to unify. UTF-8 is usually used.

Although you have set up a database in your project to use UTF-8, there is no connection method.

1. Query your own MySQL encoding method

MySQL default encoding is latin1mysql> show variables like ' character% ';  +--------------------------+--------------------------+  | Variable_name            | Value                    |  +--------------------------+--------------------------+  | character_set_client     | latin1                   |  | character_set_connection | Latin1                   | |  character_set_database   | latin1                   | |  character_set_filesystem | binary                   |  | Character_set_results |    latin1                   |  | character_set_server     | latin1                   |  | character_set_ System     | UTF8                     |  | Character_sets_dir       | D:\MySQL\share\charsets\ |  +--------------------------+--------------------------+  

2. If the project is encoded with UTF8, MySQL is also changed to UTF8 encoding. By modifying the My.ini file. Add the following items and restart the MySQL service as well.

[MySQL] default-character-set = utf8[mysql.server]default-character-set = Utf8[mysqld_safe]  default-character-set = utf8[client]default-character-set = Utf8[mysqld] Character-set-server=UTF8 collation

Java inserting Chinese into database 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.