hibernate mysql 插入中文乱码问题 插入中文直接报错
org.hibernate.exception.DataException:couldnotinsert:[contract.Contract]org.hibernate...
org.hibernate.exception.DataException: could not insert: [contract.Contract]
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:75)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:544)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:533)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:529)
contract.ContractDAO.create(ContractDAO.java:24)
contract.AddContract.execute(AddContract.java:68) 展开
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:75)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1986)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2405)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:269)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:544)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:533)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:529)
contract.ContractDAO.create(ContractDAO.java:24)
contract.AddContract.execute(AddContract.java:68) 展开
展开全部
字段type的类型为String,插入英文完全没问题,插入中文就会报上面的错误。尝试用UE或者其他支持UTF的编辑器编写一个SQL插入中文的脚本,然后MYSQL导入,如果,rIRUgS
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你建表的时候设置编码了没啊 加个这句试试 engine=innodb default character set utf8;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-05-29
展开全部
插入英文会不会报错,看下你mysql的字符集
追问
修正过来了,原来是我的字段那里没有设置成utf8
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询