欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

解决hibernate+mysql写入数据库乱码

程序员文章站 2023-12-12 08:18:34
hibernate.cfg.xml加上属性. true
hibernate.cfg.xml加上属性.
<property name="connection.useunicode">true</property>
<property name="connection.characterencoding">utf-8</property>
mysql 的驱动用3.0.15以上版本的,
加个filter, 使用utf-8字符集就可以了,
若使用spring则写在spring中的sessionfactory里即可。
例如:
<?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" />

上一篇:

下一篇: