转自:http://blog.csdn.net/jieshaowang1229/article/details/51362273
Hibernate配置文件中指定MySQL数据库的编码方式:
1)方式01
- <pre name="code" class="html"><!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- 通用配置 -->
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://127.0.0.1:3306/db?useUnicode=true&characterEncoding=utf-8</property>
- <property name="connection.username">root</property>
- <property name="connection.password">root</property>
- <!-- MySQL配置 -->
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <!-- 映射文件 -->
- <mapping resource="cn/itcast/hibernate/domain/User.hbm.xml"/>
- </session-factory>
- </hibernate-configuration>
2)方式02
- <pre name="code" class="html"><!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- 通用配置 -->
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://127.0.0.1:3306/db</property>
- <property name="connectio.useUnicode">true</property>
- <property name="connection.characterEncoding">utf-8</property>
- <property name="connection.username">root</property>
- <property name="connection.password">root</property>
- <!-- MySQL配置 -->
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- <property name="show_sql">true</property>
- <property name="format_sql">true</property>
- <!-- 映射文件 -->
- <mapping resource="com/hib/entity/Mytable.hbm.xml" />
- </session-factory>
- </hibernate-configuration>