当前位置: 首页 >数据库 > springboot+Mybatis批量改foreach抛出java.sql.SQLSyntaxErrorException

springboot+Mybatis批量改foreach抛出java.sql.SQLSyntaxErrorException

Type Exception ReportMessage Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:Description The server encountered an unexpected condition that prevented it from fulfilling the request.Exceptionorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: ### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5### The error may involve com.wawa.dao.newdao.VcgeekDao.updateNoname-Inline### The error occurred while setting parameters### SQL: update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?### Cause: java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)	com.wawa.service.system.HeaderFilter.doFilter(HeaderFilter.java:46)	org.springframework.web.filter.CharacterEncodingFilter.doFilterInteal(CharacterEncodingFilter.java:88)	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)Root Causeorg.springframework.jdbc.BadSqlGrammarException: ### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5### The error may involve com.wawa.dao.newdao.VcgeekDao.updateNoname-Inline### The error occurred while setting parameters### SQL: update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?  ;  update t_yydxx_gjc a set a.name = ? where a.id = ?### Cause: java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: 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 t_yydxx_gjc aset a.name = '找到工作,不需要' ' at line 5	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)	org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)	org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)	com.sun.proxy.$Proxy24.update(Unknown Source)	org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:254)	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)	com.sun.proxy.$Proxy38.updateNoname(Unknown Source)	com.wawa.controller.newYygl.TemplateDesignController.yydUpdateNoname(TemplateDesignController.java:207)	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)	java.lang.reflect.Method.invoke(Method.java:498)	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInteal(RequestMappingHandlerAdapter.java:690)	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)	com.wawa.utils.spring.ReloadDispatcherServlet.doDispatch(ReloadDispatcherServlet.java:27)	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)	com.wawa.service.system.HeaderFilter.doFilter(HeaderFilter.java:46)	org.springframework.web.filter.CharacterEncodingFilter.doFilterInteal(CharacterEncodingFilter.java:88)	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
连接的是mysql数据库,检查sql语法并无错误。而此处为 多条query语句,报错信息指向分号后的第二条语句。

判断可能是连接的datasource默认只允许执行单个query语句。
在连接datasource的url后面

加个allowMultiQueries=true

url=jdbc:mysql://localhost:3306/MyDb?characterEncoding=utf8&serverTimezone=GMT%2B8&allowMultiQueries=true

顺便批量修改把代码贴出来

// Daoint updateNoname(@Param("idName") ArrayList<YydxxGjcIdName> idName);//Mapper.xml<update id="updateNoname" parameterType="java.util.ArrayList"><foreach collection="idName" index="index" item="item" open="" separator=";">update t_yydxx_gjc aset a.name = #{item.name}where a.id = #{item.id}</foreach></update>

作者:尼古拉斯Brendan
来源链接:https://www.cnblogs.com/brendan/p/12875660.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/database/118085.html

标签:SQL_syntax
分享给朋友:

“springboot+Mybatis批量改foreach抛出java.sql.SQLSyntaxErrorException” 的相关文章

利用Oracle分析函数row 2022年06月03日 23:42:05
mysql 查询表 所有字段 2022年06月09日 20:38:57
查询mysql中user表 2022年06月12日 18:08:24
MYSQL查询返回JSON格式的字符串 2022年06月12日 23:10:27
MySQL查询表中的数据是否存在 2022年06月13日 13:46:57
mysql 查询当前时间 2022年06月15日 19:15:44