使用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
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
相关文章推荐
- 使用Hibernate向mysql数据库中插入 bd08 中文,数据库中显示??乱码
- 使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码
- 使用Hibernate向mysql数据库中插入中文,数据库中显示??乱码
- 使用PHP向Mysql数据库插入信息,页面中文内容显示正常,但在数据库里却是乱码,这个怎么解决?
- Oracle数据库案例整理-执行Oracle脚本失败或异常-使用SQL语句插入中文后数据库中显示乱码
- 使用hibernate往mysql数据库插入数据中文乱码问题
- 使用Hibernate框架操作Mysql数据库时,插入中文字符乱码!已解决!
- 使用Hibernate框架操作MySQL数据库插入中文字符时出现乱码
- jsp插入mysql数据库显示中文乱码问题
- php调用mysql数据库,但数据库不能显示中文呈乱码
- hibernate插入中文到mysql数据库乱码
- 数据库中文mybatis连接mysql数据库插入中文乱码
- Hibernate 数据库中插入中文显示错误
- 解决方案:在cmd中无法向数据库中插入中文?cmd显示中文是乱码?
- mysql数据库中导入数据库无法显示中文,中文乱码(解决)Window/Linux
- Linux中使用Shell脚本插入mysql数据库中文字段值乱码问题
- Linux中使用Shell脚本插入mysql数据库中文字段值乱码问题
- 往数据库插入中文的时候,显示乱码
- 【技术贴】java插入mysql中文乱码解决|java插入mysql数据库显示问号?
- hibernate插入数据库出现中文乱码问题