小白求助
Could not execute JDBC batch update解决方法
最近在学习SSH,数据库用的是oracle10G,这是我看马士兵的视频后,自己敲的代码跑出了这个错误求高手指点
数据库表结构为:id(主键),name,age
student.hbm.xml内容为:
<class name="Student" table="student">
<id name="id" column="id"></id>
<property name="name" column="name"></property>
<property name="age" column="age"></property>
</class>
Hibernate: insert into student (name, age, id) values (?, ?, ?)
Exception in thread "main"
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.
JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1215)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:382)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.lxc.hibernate.test.StudentTest.main(StudentTest.java:22)
Caused by:
java.sql.BatchUpdateException: ORA-00942: 表或视图不存在
at oracle.jdbc.driver.DatabaseError.throw
BatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
------解决方案-------------------- insert into student (name, age, id) values (?, ?, ?)
里面这个id是否和另外的表有主外键关键约束,也就是说你这个id也许在和他关系的表没有这个id
------解决方案--------------------Caused by: java.sql.BatchUpdateException: ORA-00942: 表或视图不存在
检查下数据库表
或者直接在数据库执行insert into student (name, age, id) values (?, ?, ?)看能不能成功。
------解决方案--------------------错误提示已经打印出来了。
ORA-00942: 表或视图不存在
建议:
1、检查下拼写。
2、检查数据库连接。看看登录用户是否有访问权限,用户名设置是否正确。
------解决方案--------------------看看你HIbernate.cfg.xml(applicationContext.xml)文件中的数据库配置Driver_class后面的数据库实例对象没有写错吧?