//batchLastIndex小于size本身customerAllList 75 batchCount 20 batchLastIndex 20
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
sqlSession.insert("com.idengyun.module.customer.dao.NewlyIncreasedToNCDao.saveAllCustomerListToNC",
customerAllList.subList(i, batchLastIndex));
sqlSession.commit();
sqlSession.close();
<insert id="saveAllCustomerListToNC" parameterType="java.util.List"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO [dbo].[custdoc] (
orgcode,
appcustcode,
custname,
custclass,
tel1,
ts,
status
)
VALUES
<foreach collection="list" item="m" index="index" separator=",">
(
#{ m.orgcode },#{ m.appcustcode },#{ m.custname },'C1',#{ m.tel1
},#{m.ts},'0'
)
</foreach>
</insert>
以下内容为粘贴复制,实现思路相同,这两天被这个问题坑死了,感谢这兄弟的分享!! 原文地址:
http://www.cnblogs.com/s1165482267/p/9079202.html
com.microsoft.sqlserver.jdbc.SQLServerException: 传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
看到这个异常第一个反应就是改MyBatis或SqlServer的配置,后经百度,只找到了原因:
https://blog.csdn.net/syy_c_j/article/details/52151402
SqlServer
对语句的条数和参数的数量都有限制,分别是 1000 和 2100。Mysql
对语句的长度有限制,默认是 4M。Mybatis
对动态语句没有数量上的限制
com.microsoft.sqlserver.jdbc.SQLServerException: 传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
看到这个异常第一个反应就是改MyBatis或SqlServer的配置,后经百度,只找到了原因:
https://blog.csdn.net/syy_c_j/article/details/52151402
SqlServer
对语句的条数和参数的数量都有限制,分别是 1000 和 2100。Mysql
对语句的长度有限制,默认是 4M。Mybatis
对动态语句没有数量上的限制
com.microsoft.sqlserver.jdbc.SQLServerException: 传入的请求具有过多的参数。该服务器支持最多 2100 个参数。请减少参数的数目,然后重新发送该请求。
看到这个异常第一个反应就是改MyBatis或SqlServer的配置,后经百度,只找到了原因:
https://blog.csdn.net/syy_c_j/article/details/52151402
SqlServer
对语句的条数和参数的数量都有限制,分别是 1000 和 2100。Mysql
对语句的长度有限制,默认是 4M。Mybatis
对动态语句没有数量上的限制- 在一句批量插入的操作中抛出这个异常,查看sql发现用了foreach
-
<!-- 批量插入问题件 --> <sql id="sqlInsertQuestions"> <foreach collection="questionList" item="question"> insert into cmd_Question ( qu_clm_id,qu_data_id,qu_code,qu_des,qu_fieldcode,qu_data_type ) values( #{clm_id},#{question.qu_data_id},#{question.qu_code},#{question.qu_des},#{question.qu_fieldcode},#{question.qu_data_type} ) </foreach> </sql>
之后经过尝试,只需将sql中的for循环提出至代码中进行循环即可,即
for (Question question : claim.getQuestionList()) { mapper.insertQuestion(question); }
<insert id="insertQuestion" parameterType="question"> insert into cmd_Question ( qu_clm_id,qu_data_id,qu_code,qu_des,qu_fieldcode,qu_data_type ) values( #{qu_clm_id},#{qu_data_id},#{qu_code},#{qu_des},#{qu_fieldcode},#{qu_data_type} ) </insert>