使用Mybatis框架进行批量更新(update)数据操作时报错:Translating SQLException with SQL state '42000', error code '1064',

报错信息:

DEBUG [http-nio-8080-exec-8] - Translating SQLException with SQL state '42000', error code '1064', message [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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5]; SQL was [] for task [

### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
### The error may involve com.bdqn.springmvc.dao.ItemsMapper.updateItemsList-Inline
### The error occurred while setting parameters
### SQL: update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;
### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
]
DEBUG [http-nio-8080-exec-8] - Resolving exception from handler [public java.lang.String com.bdqn.springmvc.controller.ItemsController.updatesItems(com.bdqn.springmvc.pojo.QueryVO)]: 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
### The error may involve com.bdqn.springmvc.dao.ItemsMapper.updateItemsList-Inline
### The error occurred while setting parameters
### SQL: update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;
### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
; 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
DEBUG [http-nio-8080-exec-8] - Resolving exception from handler [public java.lang.String com.bdqn.springmvc.controller.ItemsController.updatesItems(com.bdqn.springmvc.pojo.QueryVO)]: 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
### The error may involve com.bdqn.springmvc.dao.ItemsMapper.updateItemsList-Inline
### The error occurred while setting parameters
### SQL: update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;
### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
; 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
DEBUG [http-nio-8080-exec-8] - Resolving exception from handler [public java.lang.String com.bdqn.springmvc.controller.ItemsController.updatesItems(com.bdqn.springmvc.pojo.QueryVO)]: 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
### The error may involve com.bdqn.springmvc.dao.ItemsMapper.updateItemsList-Inline
### The error occurred while setting parameters
### SQL: update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;
### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
; 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
DEBUG [http-nio-8080-exec-8] - Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'error'; model is {error=未知异常!}
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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
### The error may involve com.bdqn.springmvc.dao.ItemsMapper.updateItemsList-Inline
### The error occurred while setting parameters
### SQL: update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;        update `items`        set `name` = ? , `price` = ?        where `id` = ?       ;
### 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
; 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 `items` 
      set `name` = '笔记本戴尔' , `price` = 26000.0 
      ' at line 5
    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:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
    at com.sun.proxy.$Proxy14.update(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:254)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy20.updateItemsList(Unknown Source)
    at com.bdqn.springmvc.service.impl.ItemsServiceImpl.updatesItems(ItemsServiceImpl.java:68)
    at com.bdqn.springmvc.controller.ItemsController.updatesItems(ItemsController.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

 

博主的适用处理办法:

在jdbc的配置信息上加上  &allowMultiQueries\=true (允许批量处理sql语句)。

如下图:

ItemsMapper.xml

ItemList.jsp

QueryVO.java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hi,all

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值