2023年12月2日发(作者:)

JDBC-Driver、PostgreSQL的SQL语句参数上限错误分析及解决办法(源码)JDBC-Driver、PostgreSQL的SQL语句参数上限错误分析及解决办法(源码)Mybatis + PostgreSQL-JDBC-Driver 42.1.4批量插入24178条数据(每条30字段).报如下错误:pSQL 9.6Cause: ception: An I/O error occurred while sending to the backend.; SQL []; An I/O error occurred while sending to the backend.; nested exception is ception: An I/O error occurred while sending

Tried to send an out-of-range integer as a 2-byte value: 647430没想到批量插入的顶峰在JDBC-Driver这里首先出现天花板.原因:这里是JDBC-Driver 一条SQL**参数数量达到了上限,幂增操作的参数=记录数(行)插入的字段数(列)*.JDBC-Driver 支持的参数数量跟版本(x.y.z)和类型(xx数据库)有关.解决思路:分割成小段提交.解决办法:@Servicepublic class ChPeriodicalThesisService { @Autowired private ChPeriodicalThesisMapper thesisDao; //其他 /** * . * TODO 批量插入 * @param thesisList * @return * @throws Exception */ public int insertList(List thesisList) throws Exception { return List(thesisList); } /** * . * TODO 递归:分割长List为 subNum/段。 * @param thesisList 论文list(总) * @param subNum 每段长度 (最小1) * @return * @throws Exception */ private int recurSub(List thesisList,int subNum) throws Exception{ //参数合法性判断: if(y()) return 0; if(subNum<1) return 0; //大于subNum,进入分割 if(() > subNum) {// && !(y()) //将前subNum分出来,直接插入到数据库。 //将前subNum分出来,直接插入到数据库。 List toInsert = t(0, subNum); //将subNum至最后 (剩余部分) 继续进行递归分割 List toRecurSub = t(subNum, ()); //将前subNum分出来,直接插入到数据库 && 将subNum至最后 (剩余部分) 继续进行递归分割 。统计数量 return insertList(toInsert) + recurSub(toRecurSub,subNum); //少于subNum,直接插入数据库 (递归出口) }else { //插入到数据库。统计数量 return insertList(thesisList); } } /** * . * TODO 将数据流读取并批量插入 * @param in * @return * @throws Exception */ public int readStreamAndInsertList(InputStream in) throws Exception { FileUtil fileUtil = new FileUtil(); List thesisList = FileOfChPeriodicalThesis(in); //每1500为一段 插入 return recurSub(thesisList,1500); }}源码: 欢迎交流.参考资料:效果: