两种方法:
在hibernate.cfg.xml配置文件中
- <property name="connection.url">
- jdbc:mysql://localhost:3306/hibernate4?useUnicode=true&characterEncoding=UTF-8
- </property>
- <property name="hibernate.connection.url">
- <![CDATA[jdbc:mysql://localhost:3306/hibernate4?useUnicode=true&characterEncoding=utf8]]>
- </property>
即可解决hibernate写入mysql数据库中的乱码问题