1.遇到的问题
### Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request.
; uncategorized SQLException; SQL state [S0001]; error code [8003]; The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request.
2.官方文档
根据据中 [SQL Server 的最大容量规范] 中规定,每个用户定义函数的参数个数最大为2100。(SQL Server 的最大容量规范 - SQL Server | Microsoft Learn )
3.解决办法
我是用mybatisplus批量插入,可以把list分成200条提交一次
public void batchInsertTask(OutTask task, List<OutlList> outList) {
List newList = new ArrayList<OcsoutListVo>();
int pointsDataLimit = 100;
int maxSize=outList.size() - 1;
for (int i=0; i<outList.size();i++) {
OutList clVo= outList.get(i);
OutListVo vo = new OutListVo();
vo.setRecordId(clVo.getId());
vo.setAttempt(task.getRetryCount());
newList.add(vo);
//载体list达到要求,进行批量操作
if (pointsDataLimit == newList.size() || i == maxSize) {
//调用批量插入
outListMapper.batchInsertOutList(newList, task.getCode());
//每次批量操作后,清空载体list,等待下次的数据填入
newList.clear();
}
}
4.总结
批量插入还可以引入多线程操作。
提示语:大成者大累,大智者大忧,无能者无欲无求。