请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师老师老师

https://img1.sycdn.imooc.com//szimg/5ae88cfa000178db06570379.jpg

前端传过来的List<A> 对象

当List只有一个元素时可以更新数据库

但是List传过来的有两个元素时就报错  

这是什么问题

正在回答 回答被采纳积分+3

9回答

提问者 qq_京都声_03857642 2018-05-12 10:57:23

弄好了老师  allowMultiQueries=true  少了个参数  哎  

0 回复 有任何疑惑可以回复我~
  • Geely #1
    赞,解决了就好,这个错误还挺明显的,辛苦同学啦~~赞解决能力
    回复 有任何疑惑可以回复我~ 2018-05-13 23:59:40
提问者 qq_京都声_03857642 2018-05-08 17:31:59
 SQL: update activedetail      SET region = ?        where id = ?      ;      update activedetail      SET region = ?        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 activedetail
     SET region = 'a' 
      where id = 2' at line 5


0 回复 有任何疑惑可以回复我~
  • 提问者 qq_京都声_03857642 #1
    把其它参数删了只剩下region和id也还不行
    回复 有任何疑惑可以回复我~ 2018-05-08 17:35:04
提问者 qq_京都声_03857642 2018-05-07 16:53:02
2018-05-07 16:43:32,513 DEBUG com.cn.hnust.dao.ActiveDetailMapper.updateByCollection - ==>  Preparing: update activedetail SET region = ?, inorout = ?, theme = ?, date1 = ?, date2 = ?, sextype = ?, description = ?, fileLIst2 = ? where id = ? ; update activedetail SET region = ?, inorout = ?, theme = ?, date1 = ?, date2 = ?, sextype = ?, description = ?, fileLIst2 = ? where id = ? 
2018-05-07 16:43:32,520 DEBUG com.cn.hnust.dao.ActiveDetailMapper.updateByCollection - ==> Parameters: shanxi(String), false(String), java.io.StringReader@5d8a1b24(StringReader), java.io.StringReader@503261b(StringReader), java.io.StringReader@c034be7(StringReader), java.io.StringReader@ff6ab48(StringReader), java.io.StringReader@2a8c2a9(StringReader), java.io.StringReader@1e070f19(StringReader), 7(Integer), e(String), e(String), java.io.StringReader@84d334d(StringReader), java.io.StringReader@325b65e7(StringReader), java.io.StringReader@76a2548f(StringReader), java.io.StringReader@507be285(StringReader), java.io.StringReader@314d749c(StringReader), java.io.StringReader@58d05b0f(StringReader), 2(Integer)


0 回复 有任何疑惑可以回复我~
Geely 2018-05-06 20:21:15

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 activedetail

     SET region = 'e',

      inorout = 'e',

      theme = 'e' at line 12


仔细看了一下,这个sql,看样子就是sql出问题了,同学把sql的日志打印出来,看看打印出要执行的sql是什么样,然后在客户端跑一下,找到语法错误即可。

0 回复 有任何疑惑可以回复我~
  • 提问者 qq_京都声_03857642 #1
    老师  我还是没找到错误  麻烦老师帮忙看下  sql在上面的回复
    回复 有任何疑惑可以回复我~ 2018-05-07 16:52:53
提问者 qq_京都声_03857642 2018-05-06 00:47:09
<script>
import store from '@/vuex/store';
export default {
data() {
return {
form: {
id:'',
theme: '',
region: '',
date1:'',
date2:'',
inorout: false,
sextype: [],
description: '',
filelist2: []
},
}
},
store,
methods:{
update(e){
e.preventDefault();
var params = new URLSearchParams();

var multipleSelectionn= new Array();
this.$store.state.multipleSelection.forEach((item, index) => {
this.form.id=item.id;
this.form.theme=item.theme;
this.form.region=item.region;
this.form.date1=item.date1;
this.form.date2=item.date2;
this.form.sextype=item.sextype;
this.form.description=item.description;
this.form.filelist2=item.filelist2;
multipleSelectionn.push(this.form);



});
params.append("multipleSelectionn",JSON.stringify(multipleSelectionn));
this.$ajax({
method: 'post',
url: 'http://localhost:8080/account/update',
traditional: true,
data: params,
}).then((response) => {

}, (response) => {
});
}
}
}
</script>


0 回复 有任何疑惑可以回复我~
提问者 qq_京都声_03857642 2018-05-06 00:45:07
@RequestMapping(value="/update",method=RequestMethod.POST)
    @ResponseBody
    public boolean Update(String multipleSelectionn){
       
  
        List<ActiveDetailWithBLOBs>  collection = JSONObject.parseArray(multipleSelectionn, ActiveDetailWithBLOBs.class);

        iAccountService.updateActiveDetail(collection);
        return true;
    }


0 回复 有任何疑惑可以回复我~
提问者 qq_京都声_03857642 2018-05-02 23:55:56
multipleSelection:
[{"id":7,"region":"shanxi","inorout":"true","theme":"mkl","date1":"Thu May 03 2018 00:00:00 GMT+0800 (中国标准时间)","date2":"Tue May 01 2018 22:39:28 GMT+0800 (中国标准时间)","sextype":"女,均可","description":"测试啊测试","filelist2":"[{\"name\":\"food.jpeg\",\"url\":\"https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100\",\"uid\":1525185559105,\"status\":\"success\"},{\"name\":\"food2.jpeg\",\"url\":\"https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100\",\"uid\":1525185559106,\"status\":\"success\"}]"},{"id":2,"region":"e","inorout":"e","theme":"eop","date1":"e","date2":"e","sextype":"e","description":"e","filelist2":"e"}]

这是Form Data中的数据

0 回复 有任何疑惑可以回复我~
提问者 qq_京都声_03857642 2018-05-02 23:52:06
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is 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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
### The error may involve com.cn.hnust.dao.ActiveDetailMapper.updateByCollection-Inline
### The error occurred while setting parameters
### SQL: update activedetail      SET region = ?,       inorout = ?,       theme = ?,       date1 = ?,       date2 = ?,       sextype = ?,       description = ?,       fileLIst2 = ?        where id = ?      ;      update activedetail      SET region = ?,       inorout = ?,       theme = ?,       date1 = ?,       date2 = ?,       sextype = ?,       description = ?,       fileLIst2 = ?        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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
; 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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
### The error may involve com.cn.hnust.dao.ActiveDetailMapper.updateByCollection-Inline
### The error occurred while setting parameters
### SQL: update activedetail      SET region = ?,       inorout = ?,       theme = ?,       date1 = ?,       date2 = ?,       sextype = ?,       description = ?,       fileLIst2 = ?        where id = ?      ;      update activedetail      SET region = ?,       inorout = ?,       theme = ?,       date1 = ?,       date2 = ?,       sextype = ?,       description = ?,       fileLIst2 = ?        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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
; 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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235)
	org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
	org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
	com.sun.proxy.$Proxy19.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.$Proxy22.updateByCollection(Unknown Source)
	com.cn.hnust.service.impl.AccountServiceImpl.updateActiveDetail(AccountServiceImpl.java:63)
	com.cn.hnust.controller.AccountController.Update(AccountController.java:85)
	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.doInvoke(InvocableHandlerMethod.java:209)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root 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 activedetail
     SET region = 'e',
      inorout = 'e',
      theme = 'e' at line 12
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
	com.mysql.jdbc.Util.getInstance(Util.java:384)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
	com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
	com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
	com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
	com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1307)
	org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:169)
	org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
	org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
	org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
	org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
	org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
	org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
	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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	com.sun.proxy.$Proxy19.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.$Proxy22.updateByCollection(Unknown Source)
	com.cn.hnust.service.impl.AccountServiceImpl.updateActiveDetail(AccountServiceImpl.java:63)
	com.cn.hnust.controller.AccountController.Update(AccountController.java:85)
	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.doInvoke(InvocableHandlerMethod.java:209)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)


0 回复 有任何疑惑可以回复我~
polo哦 2018-05-02 09:52:20

为什么你的分隔符是;。。。很明显就是,  你在sql里面有见过;做分隔符?

0 回复 有任何疑惑可以回复我~
  • 提问者 qq_京都声_03857642 #1
    ,不对我改成的;
    因为如果separator是,
    打印出来的sql语句是,分隔的
    所以我换成的;
    回复 有任何疑惑可以回复我~ 2018-05-02 16:51:03
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号