《Mysql實例解決hibernate+mysql寫入數(shù)據(jù)庫亂碼》要點:
本文介紹了Mysql實例解決hibernate+mysql寫入數(shù)據(jù)庫亂碼,希望對您有用。如果有疑問,可以聯(lián)系我們。
hibernate.cfg.xml加上屬性.
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
mysql 的驅(qū)動用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" />
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/5188.html