今天使用Hibernate写 helloworld程序 ,发现向mysql表中插入中文都显示"???"乱码,经过更改配置已经成功处理该问题 ,现分享如下 。
插入mysql为乱码时候 Hibernate配置文件 如下
/p>
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/hibernate
root
123456
org.hibernate.dialect.MySQLDialect
thread
org.hibernate.cache.NoCacheProvider
true
update
修改 以下设置即可向数据库中插入中文了
name="connection.url">jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF8