`

Incorrect string value: '\xE5\x86\x99\xE7\x9A\x84...'

阅读更多

测试环境:MySql5.1+Hibernate3.5+MyEclipase8

 

原因:我在项目中向mysql插入中文字符为乱码,于是我将mysql安装目录下的my.ini文件中的default-character-set修改为gb2312。然后再次执行java代码,抛出如下异常:

 

737 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1366, SQLState: HY000

737 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Incorrect string value: '\xE5\x86\x99\xE7\x9A\x84...' for column 'c_commentContent' at row 1

org.hibernate.exception.GenericJDBCException: could not insert: [com.hx.mode.Comment]

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:2329)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2836)

at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)

at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)

at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)

at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)

at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)

at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)

at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)

at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)

at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)

at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)

at com.hx.dao.impl.CommentDaoImpl.save(CommentDaoImpl.java:76)

at com.hx.dao.impl.CommentDaoImplTest.testSave(CommentDaoImplTest.java:20)

at com.hx.dao.impl.CommentDaoImplTest.main(CommentDaoImplTest.java:8)

Caused by: java.sql.SQLException: Incorrect string value: '\xE5\x86\x99\xE7\x9A\x84...' for column 'c_commentContent' 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.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)

at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)

 

解决办法:

使用mysql的配置工具重新配置一个新的实例(设置编码为gb2312),



 

然后在将原来数据库的表重建(因为在创建表时DEFAULT CHARSET=latin1)

 

 

 

  • 大小: 67.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics