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