首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

学习hibernate时出现的有关问题

2012-06-09 
学习hibernate时出现的问题16:01:41,060WARN JDBCExceptionReporter:77 - SQL Error: 1366, SQLState: HY0

学习hibernate时出现的问题
16:01:41,060 WARN JDBCExceptionReporter:77 - SQL Error: 1366, SQLState: HY000
16:01:41,060 ERROR JDBCExceptionReporter:78 - Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
16:01:41,060 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.guoxin.model.Dog.main(Dog.java:24)
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 8 more
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.guoxin.model.Dog.main(Dog.java:24)
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 8 more

检查了语句都没什么问题!
<hibernate-configuration>

  <session-factory>
  <property name="hbm2ddl.auto">update</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/cf?characterEncoding=utf-8</property>
  <property name="connection.username">root</property>


  <property name="connection.password">1111</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="myeclipse.connection.profile">localhost</property>
  <mapping class="com.guoxin.common.DogManager"/>
  </session-factory>

</hibernate-configuration>
这里是关于hibernate的配置!我将上面的中文转化删除掉就可以存入数据库而不报错!但是存入的中文数据是乱码!




[解决办法]
http://apps.hi.baidu.com/share/detail/31586999

看看这个吧
[解决办法]
楼上那个不是楼主要找的问题。
很久没用hibernate了, 不过错误很明显,错误的中文值, 
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE4\xBD\xA0\xE5\xA5\xBD' for column 'name' at row 1
你的name用了中文,1.检查中文值是否有什么异常. 2.你的name估计是从请求中获取到的, 你可以试试将name的值以请求的编码格式进行解码, 然后用UTF-8的方式编码(手动转化为UTF-8)再保存到数据库
[解决办法]
保存前中文乱码问题?
[解决办法]
在数据库插入前得到的是乱码!从此入手吧

热点排行