mybatis批量操作报错

来源:互联网 发布:sql删除语句大全 编辑:程序博客网 时间:2024/05/17 02:58

在公司项目开发过程中涉及到使用批量更新数据的操作,遇到如下错误:

org.springframework.jdbc.BadSqlGrammarException:   ### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update `am_counpons_details`               SET `cd_custId` = '555'                WHERE ' at line 6  ### The error may involve com.smi.am.dao.AmCounponsDetailsMapper.batchUpdatePackageIdByCouponsIds-Inline  ### The error occurred while setting parameters  ### SQL: update `am_counpons_details`           SET `cd_custId` = ?            WHERE `cd_detailId` = ?            ;    update `am_counpons_details`           SET `cd_custId` = ?            WHERE `cd_detailId` = ?            ;  ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update `am_counpons_details`               SET `cd_custId` = '555'                WHERE ' at line 6  ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update `am_counpons_details`               SET `cd_custId` = '555'                WHERE ' at line 6      at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)      at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)      at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)      at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)      at com.sun.proxy.$Proxy87.update(Unknown Source)      at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:295)      at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:59)      at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)      at com.sun.proxy.$Proxy119.batchUpdatePackageIdByCouponsIds(Unknown Source)      at com.smi.am.service.RedisTest.testBatchUpdate(RedisTest.java:59)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update `am_counpons_details`               SET `cd_custId` = '555'                WHERE ' at line 6      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)      at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)      at com.mysql.jdbc.Util.getInstance(Util.java:387)      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)      at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)      at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)      at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at net.bull.javamelody.JdbcWrapper.doExecute(JdbcWrapper.java:404)      at net.bull.javamelody.JdbcWrapper$StatementInvocationHandler.invoke(JdbcWrapper.java:129)      at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:286)      at com.sun.proxy.$Proxy98.execute(Unknown Source)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)      at com.sun.proxy.$Proxy99.execute(Unknown Source)        at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)      at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)      at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)      at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)      at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)      at com.sun.proxy.$Proxy95.update(Unknown Source)      at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:606)      at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)      ... 35 more  

用mybatic 批量更新必须在数据源url加上参数&allowMultiQueries=true,意思是允许一次进行多个sql操作

原创粉丝点击