码上敲享录 > mybatis的常见问题 > SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100

SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100

上一章章节目录下一章 2019-09-21已有4523人阅读 评论(0)

报错环境springboot+mybatis,mybatis批量插入

@Insert("<script> INSERT INTO pushHistory (id,openId,patientId,tid,first,keyword1,keyword2,keyword3,keyword4," +
" keyword5,remark,createTime,flag,type,success) " +
" <foreach collection='result2' item='item' index='index' > \n" +
" select #{item.id},#{item.openId},#{item.patientId},#{item.tid},#{item.first},#{item.keyword1},#{item.keyword2},\n" +
" #{item.keyword3},#{item.keyword4},#{item.keyword5},#{item.remark},getDate(),#{item.flag},#{item.type},#{i} " +
" <if test='index != (result2.size() - 1)'> union all </if>" +
" </foreach> </script> ")
void insertBatchHistory(@Param(value = "result2")List<ListResult> result2,@Param(value = "i")int i);

找到的原因是传输的sql语句过长
报错语句如下(截取了部分报错sql):

org.springframework.jdbc.UncategorizedSQLException:

### Error updating database.  Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100。

### The error may involve com.xinshai.dao.ResultPushMsgDao.insertBatchHistory-Inline

### The error occurred while setting parameters

### SQL: INSERT INTO pushHistory (id,openId,patientId,tid,first,keyword1,keyword2,keyword3,keyword4, keyword5,remark,createTime,flag,type,success)       select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all        select ?,?,?,?,?,?,?,   ?,?,?,?,getDate(),?,?,?    union all   ()      

### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100。

; uncategorized SQLException; SQL state [S0001]; error code [8003]; 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确。此 RPC 请求中提供了过多的参数。最多应为 2100。

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) ~[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.0.5.RELEASE.jar:5.0.5.RELEASE]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[mybatis-spring-1.3.1.jar:1.3.1]


报错语句,这是原本报错语句:原因是result3这个List集合长度太长

resultPushMsgServices.insertBatchHistory(result3,1);


解决方法:将list集合改为批量插入,每次插入100条

int toIndex=100;
for(int j=0;j<result3.size();j+=100  ){

//作用为toIndex最后没有100条数据则剩余几条newList中就装几条

if(j+100>result3.size()){        

toIndex=result3.size()-j;
}
List newResult3 = result3.subList(j,j+toIndex);
resultPushMsgServices.insertBatchHistory(newResult3,1);



向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交