您的位置:首页 > 数据库 > MySQL

使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码

2013-08-07 22:28 447 查看
通过网上学习,要求修改Hibernate的配置文件hibernate.cfg.xml,将原来的

jdbc:mysql://localhost:3306/shopping

改为

jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=utf-8

但是又出现以下异常:

org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2019)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1931)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1910)

at action.AddProduct.(AddProduct.java:22)

Caused by: org.dom4j.DocumentException: Error on line 9 of document : The reference to entity "characterEncoding" must end with the ';' delimiter. Nested exception: The reference to entity "characterEncoding" must end with the ';' delimiter.

at org.dom4j.io.SAXReader.read(SAXReader.java:482)

at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2011)

... 3 more

Exception in thread "main" java.lang.NullPointerException

at action.AddProduct.save(AddProduct.java:33)

at action.AddProduct.main(AddProduct.java:94)

折腾半天才发现需要将&进行转码,作如下更改。

jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=utf-8
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐