Solve the garbled problem of hibernate + MySQL database writing
Source: Internet
Author: User
Hibernate. cfg. XML adds attributes.
<Property name = "connection. useunicode"> true </property>
<Property name = "connection. characterencoding"> UTF-8 </property>
MySQL drivers are later than 3.0.15,
Add a filter and use the UTF-8 character set,
If spring is used, write it in sessionfactory in spring.
For example:
<? XML version = '1. 0' encoding = 'utf-8'?>
<! Doctype hibernate-configuration public
"-// Hibernate/hibernate configuration DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<! -- Generated by myeclipse hibernate tools. -->
<Hibernate-configuration>
<Session-factory>
<Property name = "connection. username"> root </property>
<Property name = "connection. url">
JDBC: mysql: // localhost: 3306/hibernate_table
</Property>
<Property name = "dialect">
Org. hibernate. dialect. mysqldialect
</Property>
<Property name = "myeclipse. Connection. Profile">
MySQL hibernatetable
</Property>
<Property name = "connection. Password"> 12345678 </property>
<Property name = "connection. driver_class">
Com. MySQL. JDBC. Driver
</Property>
<Property name = "connection. useunicode"> true </property>
<Property name = "connection. characterencoding"> UTF-8 </property>
<Property name = "show_ SQL"> true </property>
<Property name = "format_ SQL"> true </property>
<Mapping Resource = "cN/COM/hibernate/demo/guestbook. HBM. xml"/>
<Mapping Resource = "cN/COM/hibernate/demo/gmapping. HBM. xml"/>
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.