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

很文博客hinven.com 数据库评论105字数 1251阅读模式
广告也精彩

初次没习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" />文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/51192.html

文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/51192.html

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证