Hibernate与mysql 乱码问题
<?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/database?useUnicode=true&characterEncoding=UTF-8
</property>
<property name=”dialect”>
org.hibernate.dialect.MySQLDialect
</property>
<property name=”myeclipse.connection.profile”>xing</property>
<property name=”connection.password”>wen</property>
<property name=”connection.driver_class”>
com.mysql.jdbc.Driver
</property>
<mapping resource=”hi/News.hbm.xml” />
<mapping resource=”hi/Guestbook.hbm.xml” />
</session-factory>
</hibernate-configuration>
以上是一个 hibernate.cfg.xml 文件内容
解决中文乱码的是以下代码:
<property name=”connection.url”>
jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8
</property>
在连接数据库后面添加字符集为utf-8
不然的话会报错:must be end with ‘;’