您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

bubuko 2022/1/25 19:50:41 java 字数 10290 阅读 1109 来源 http://www.bubuko.com/infolist-5-1.html

连接的是mysql数据库,检查sql语法并无错误。而此处为 多条query语句,报错信息指向分号后的第二条语句。 判断可能是连接的datasource默认只允许执行单个query语句。 在连接datasource的url后面 加个allowMultiQueries=true url=jdbc\:my ...
Type Exception Report

Message Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.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 a
            set 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 a
            set 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 a
            set 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.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
Root Cause

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 a
            set 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 a
            set 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 a
            set 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.handleInternal(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.doFilterInternal(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

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

// Dao
int 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 a
            set a.name = #{item.name}
            where a.id = #{item.id}
        </foreach>
    </update>

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

原文:https://www.cnblogs.com/brendan/p/12875660.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶