Hibernate insert Chinese to MySQL database garbled

Source: Internet
Author: User

1. Changing the MySQL database character set


Modify/ETC/MY.CNF under Linux

Modify My.ini under Windows


[Mysqld]
#default-character-set = UTF8

Character_set_server=utf8 #这个是我添加的
init_connect= ' SET NAMES UTF8 '
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
User=mysql
Symbolic-links=0

[Mysqld_safe]
Default-character-set = UTF8 #这个是我添加的
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid

[Client]
Default-character-set = UTF8 #这个是我添加的

[Mysql.server]
Default-character-set = UTF8 #这个是我添加的

[MySQL]
Default-character-set = UTF8 #这个是我添加的


Mysql> Show variables like '%char% ';


| character_set_client | UTF8 |

| character_set_connection | UTF8 |

| Character_set_database | UTF8 |

| Character_set_filesystem | binary |

| Character_set_results | UTF8 |

| Character_set_server | UTF8 |

| Character_set_system | UTF8 |

| Character_sets_dir | /usr/share/mysql/charsets/|



2 Data Source URL connection configuration


When you configure a database URL in an XML configuration file, you use the & escape character, which is &amp

<property name= "url" value= "Jdbc:mysql://localhost:3306/customer? Useunicode=true&amp;characterencoding=utf8 "</property>

3.Tomcat

The Tomcat default character set is Iso-8829-1, modified to Utf-8

Modify the Server.xml file

<connector connectiontimeout= "20000" port= "8080" protocol= "http/1.1" redirectport= "8443" URIEncoding= "Utf-8"/ >



Differences in use of UTF8 and UTF-8


Summary: "Utf-8" can only be used in MySQL with the alias "UTF8", but in other places use uppercase "UTF-8". 】


This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1672424

Hibernate insert Chinese to MySQL 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.