com.microsoft.sqlserver.jdbc.SQLServerException: 傳入的請求具有過多的參數。該服務器支持最多 2100 個參數
針對這個錯誤網上有很多解決辦法,但最終都沒能解決掉我遇到的問題,實際是因爲數據量過大而造成的錯誤,下面是批量插入數據的代碼:
MyBatis xml SQL語句如下:
<insert id="insertRainListing">
INSERT INTO ST_SDP_R(STCD,TM,MI10,MI30,HH1,HH3,HH6,HH12,HH24) VALUES
<foreach item="map" index="index" collection="list" open="" separator="," close="">
(
#{map.STCD},#{map.TM},#{map.MI10},#{map.MI30},#{map.HH1},#{map.HH3},#{map.HH6},NULL,NULL
)
</foreach>
</insert>
List<HashMap<String,String>> list = dao.getAllRecords(QueryBean queryBean);
int batchNum = 0;
int maxSize = list.size();
List<HashMap<String,String>> temp = new ArrayList<HashMap<String,String>>();
for(int i=0;i<maxSize;I++){
if(batchNum<200){
temp.add(list.get(i));
batchNum++;
}else{
invoke create function;
batchNum = 0;
temp = new ArrayList<HashMap<String,String>>();
}
}
invoke create function;
搞定!
這樣就完成了Java批量插入