异常 java.sql.SQLException:不正确的字符串值:'\xF0\x9F\x92\xBC' 列 'Rins' 在第 1 行
Posted
技术标签:
【中文标题】异常 java.sql.SQLException:不正确的字符串值:\'\\xF0\\x9F\\x92\\xBC\' 列 \'Rins\' 在第 1 行【英文标题】:Exception java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\xBC' for column 'Rins' at row 1 at异常 java.sql.SQLException:不正确的字符串值:'\xF0\x9F\x92\xBC' 列 'Rins' 在第 1 行 【发布时间】:2014-07-03 11:00:53 【问题描述】:2014-05-14 08:41:02
Error in : org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1154)
org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:695)
sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
com.sun.proxy.$Proxy82.merge(Unknown Source)
com.REP.CompanyAcce.pat.dao.BaseDAO.save(BaseDAO.java:50)
sun.reflect.GeneratedMethodAccessor250.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
com.sun.proxy.$Proxy84.save(Unknown Source)
com.REP.CompanyAcce.pat.service.PATThreadService.saveCandidatesData(PATThreadService.java:561)
com.REP.CompanyAcce.pat.service.PATThreadService.collectCandidateData(PATThreadService.java:200)
com.REP.CompanyAcce.pat.service.PATThreadService$CollectCandidateDataThread.run(PATThreadService.java:90)
java.lang.Thread.run(Thread.java:662)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
java.lang.Thread.run(Thread.java:662)
org.hibernate.exception.GenericJDBCException: could not insert: [com.REP.CompanyAcce.pat.entity.PATCandidatesData]javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [com.REP.CompanyAcce.pat.entity.PATCandidatesData] at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1215) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1148) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1154) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:695) at sun.reflect.GeneratedMethodAccessor193.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) at com.sun.proxy.$Proxy82.merge(Unknown Source) at com.REP.CompanyAcce.pat.dao.BaseDAO.save(BaseDAO.java:50) at sun.reflect.GeneratedMethodAccessor250.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at com.sun.proxy.$Proxy84.save(Unknown Source) at com.REP.CompanyAcce.pat.service.PATThreadService.saveCandidatesData(PATThreadService.java:561) at com.REP.CompanyAcce.pat.service.PATThreadService.collectCandidateData(PATThreadService.java:200) at com.REP.CompanyAcce.pat.service.PATThreadService$CollectCandidateDataThread.run(PATThreadService.java:90) at java.lang.Thread.run(Thread.java:662) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662) Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [com.REP.CompanyAcce.pat.entity.PATCandidatesData] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2345) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2852) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320) at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129) at org.hibernate.ejb.event.EJB3MergeEventListener.saveWithGeneratedId(EJB3MergeEventListener.java:62) at org.hibernate.event.def.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:415) at org.hibernate.event.def.DefaultMergeEventListener.mergeTransientEntity(DefaultMergeEventListener.java:341) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:303) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:258) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:686) ... 23 more Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\xBC' for column 'HEADLINE' at row 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318) at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57) ... 40 more
我创建了这样的表:-
DROP TABLE IF EXISTS `aa`;
CREATE TABLE `aa` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Rins` varchar(45) NOT NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
然后
ALTER TABLE aa MODIFY Rins VARCHAR(45) CHARACTER SET UTF8 整理 utf8_polish_ci;
但我仍然遇到异常
原因:java.sql.SQLException:不正确的字符串值: '\xF0\x9F\x92\xBC' 用于 com.mysql.jdbc.SQL 的第 1 行的列 'Rins'
【问题讨论】:
` '\xF0\x9F\x92\xBC'` 不是 UTF-8 '\xF0\x9F\x92\xBC' 是 Encoding 。真实的文字可能会有所不同。 显示您插入的相关源代码和数据。 那么当你尝试在表格中插入一个普通的波兰语单词时会发生什么? 这是 Excel 表格。我必须在其中给出4个位置。名字、姓氏、电子邮件、LinkedInURL 【参考方案1】:错误所指的字符“U+1F4BC”是mysql中utf8不支持的补充字符。 You should try using utf8mb4 instead.
对于增补字符,utf8 根本无法存储该字符,而 utf8mb4 需要四个字节来存储它。由于 utf8 根本无法存储字符,因此 utf8 列中没有任何补充字符,从旧版本的 MySQL 升级 utf8 数据时无需担心转换字符或丢失数据。
【讨论】:
【参考方案2】:我猜你只是在使用 utf-8。
在你的 CREATE TABLE 中试试这个...
`Rins` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL
utf-8 只支持Basic Multilingual Planes 其中你的特殊字符不属于。所以你必须使用 utf8mb4 代替
你的Mysql应该是5.5+
这个帖子可以给你更多的解释...java.sql.SQLException: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F…'
【讨论】:
我正在使用 Mysql 5.5,所以我可以得到解决方案吗?? 是的...在这里Mysql-Documentation以上是关于异常 java.sql.SQLException:不正确的字符串值:'\xF0\x9F\x92\xBC' 列 'Rins' 在第 1 行的主要内容,如果未能解决你的问题,请参考以下文章
获取异常 java.sql.SQLException:套接字创建错误
java.sql.SQLException:Io 异常:套接字读取超时与关闭连接
java.sql.SQLException:Io 异常:指定了未知主机
这个异常是啥意思?java.sql.SQLException: General error , in Java with Access DB?