当前位置: 首页 > 图文教程 > 数据库 > MYSQL > 解决hibernate+mysql写入数据库乱码

MYSQL
Timeout error occurred trying to start MySQL Daemon
Phpcms2008网站内容管理系统免费开源
PHP教程:常用mysql操作
MySQL教程:Order By用法
MYSQL导入数据Got a packet bigger than...错误
MySQL安装向导所作的更改
MySQL教程:Order By索引优化
MySQL教程:Order By语法
MySQL教程:Order By Rand()
MySQL教程:Replace INTO说明
MySQL server has gone away问题原因
MySQL教程:Group By用法
MySQL命令终端有beep声
mysql与sqlserver的所有区别
SQLite数据库最适合做网站内容管理系统(CMS)
mysql proxy问题
Windows下PHP+MySQL+IIS安全平台搭建
e2php搭建Windows下Apache+PHP+MySQL环境
PHP简单学习,保证入门学会
MYSQL的DATE_FORMAT()格式化日期

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 152 ::
收藏到网摘: n/a

初次没习hibernate,其中遇到问题在网上找的答案与大家共同分享! 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" />