Caused by java sql BatchUpdateException Can not issue exec

1、错误描述

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [select student_id from b_student where student_code=? ]; Can not issue executeUpdate() for SELECTs; nested exception is java.sql.BatchUpdateException: Can not issue executeUpdate() for SELECTs
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:100)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:673)
	at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:989)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.BatchUpdateException: Can not issue executeUpdate() for SELECTs
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1815)
	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1277)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2596)
	at com.alibaba.druid.filter.FilterAdapter.statement_executeBatch(FilterAdapter.java:2474)
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeBatch(FilterEventAdapter.java:279)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeBatch(FilterChainImpl.java:2594)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeBatch(StatementProxyImpl.java:192)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeBatch(DruidPooledPreparedStatement.java:559)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1005)
	at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:989)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)
	... 46 more
Caused by: java.sql.SQLException: Can not issue executeUpdate() for SELECTs
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2113)
	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1773)
	... 56 more

2、错误原因

this.getJdbcTemplate().batchUpdate(SQL,new BatchPreparedStatementSetter(){
	public int getBatchSize()
        {
	return list.size();
        }

	@Override
	public void setValues(PreparedStatement ps, int i)throws SQLException{

	}
});

在JdbcTemplate批量添加或修改的SQL语句,应该是insert into 或update语句,但是这里写成了select查询语句

3、解决办法

(1)如果是批量新增或修改操作,SQL语句要是insert into 或 update 语句

(2)如果是批量查询操作,SQL是select语句,但是不能调用batchUpdate方法

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

原文地址:https://www.cnblogs.com/odejsjhshw/p/10373544.html

时间: 2024-12-10 03:02:48

Caused by java sql BatchUpdateException Can not issue exec的相关文章

Caused by:java.sql.BatchUpdateException:ORA-02291

1.错误描述 Caused by:java.sql.BatchUpdateException:ORA-02291:违反完整约束条件(PEKING.FKA844BA60FCCDD33)-未找到父项关键字 2.错误原因 3.解决办法

java.sql.SQLException: Can not issue empty query.

1.错误叙述性说明 java.sql.SQLException: Can not issue empty query. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:

Caused by: java.sql.SQLException: Operand should contain 1 column(s)

1.错误描述 [ERROR:]2015-05-05 15:48:55,847 [异常拦截] org.hibernate.exception.DataException: error executing work at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135) at org.hibernate.exception.internal.

Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

解决sqoop导入报错:Caused by: java.sql.SQLException: Protocol violation

报错信息: 2017-06-15 15:02:15,374 INFO [main] org.apache.hadoop.mapred.MapTask: Ignoring exception during close for [email protected]0 java.io.IOException: java.sql.SQLException: Protocol violation at org.apache.sqoop.mapreduce.db.DBRecordReader.close(DB

Caused by: java.sql.SQLException: Couldn't perform the operation commit

1.错误描述 Caused by: java.sql.SQLException: Couldn't perform the operation commit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs). at org.logicalcobwebs.proxool.WrappedConnecti

Caused by: java.sql.SQLException: Field 'id' doesn't have a default value

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

Caused by: java.sql.SQLException: ResultSet is from UPDATE. No Data.

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

Error updating database. Cause: java.sql.BatchUpdateException: Field 'id' doesn't have a default value

异常信息 ### Error updating database. Cause: java.sql.BatchUpdateException: Field 'id' doesn't have a default value Query is: INSERT INTO `test`.`order` ( `order`.`code`, `order`.`create_date`, `order`.`status`, ) VALUES ( ?, ?, 原因 数据库表设计时候id没有加自动增长 myba