再做詳解之前,我們先來了解一下jdbctemplate批量操作的5個api介面:
這個方法相對來說比較簡單,不做詳細解析,該方法主要是將提供的sql列表作為乙個batch進行執行,每個sql的update count可以通過返回int的長度計算來獲得
1. 介面api原始碼
int batchupdate(string sql, batchpreparedstatementsetter pss) throws dataacces***ception;
2. 介面api原始碼實現
public int batchupdate(string sql, final batchpreparedstatementsetter pss) throws dataacces***ception
int result = execute(sql, (preparedstatementcallback) ps ->
ps.addbatch();
}return ps.executebatch();
}else
rowsaffected.add(ps.executeupdate());
}int rowsaffectedarray = new int[rowsaffected.size()];
for (int i = 0; i < rowsaffectedarray.length; i++)
return rowsaffectedarray;}}
finally
}});
assert.state(result != null, "no result array");
return result;
3. 使用方法
public int batchinsert(listtblstockorderitembarcodes, jdbctemplate jdbctemplate)
@override
public int getbatchsize()
});int suminsertedcount = 0;
for (int a : updatecountarray)
return suminsertedcount;
}
1.介面api原始碼
int batchupdate(string sql, listbatchargs) throws dataacces***ception;
2.介面api原始碼實現
@override
public int batchupdate(string sql, listbatchargs) throws dataacces***ception
@override
public int batchupdate(string sql, listbatchargs, final int argtypes) throws dataacces***ception
return batchupdate(
sql,
new batchpreparedstatementsetter()
else
else
statementcreatorutils.setparametervalue(ps, colindex, coltype, value);}}
}@override
public int getbatchsize()
});}
3. 使用方法
public int batchupdate(listtblstocks, jdbctemplate jdbctemplate) ;
}).collect(collectors.tolist());
int updatecountarray = jdbctemplate.batchupdate(insertstocksql, batchargs);
return updatecountarray.length;
}
1. 介面api原始碼
int batchupdate(string sql, collectionbatchargs, int batchsize,
parameterizedpreparedstatementsetterpss) throws dataacces***ception;
2. 介面api原始碼實現
public int batchupdate(string sql, final collectionbatchargs, final int batchsize,
final parameterizedpreparedstatementsetterpss) throws dataacces***ception
int result = execute(sql, (preparedstatementcallback) ps ->
rowsaffected.add(ps.executebatch());}}
else );}}
int result1 = new int[rowsaffected.size()];
for (int i = 0; i < result1.length; i++)
return result1;
}finally
}});
assert.state(result != null, "no result array");
return result;
}
3. 使用方法
public int batchupdate(listtblstocks, jdbctemplate jdbctemplate) ;
}).collect(collectors.tolist());
int updatecountarray = jdbctemplate.batchupdate(insertstocksql, batchargs);
return updatecountarray.length;
}
3. 使用方法
public int batchinsert(listtblstocks, jdbctemplate jdbctemplate) ));
int suminsertedcount = 0;
for(int i = 0; i < batchresult.length; i++)
}return suminsertedcount;
}
SharedPreferences的四種模式
開發應用需要儲存一些配置引數,如果是window軟體通常我們會採用ini檔案進行儲存,如果是j2se應用,我們會採用properties屬性檔案進行儲存。如果是android應用,我們最適合採用sharedpreferences儲存資料,它是乙個輕量級的儲存類,特別適合用於儲存軟體配置引數。使用sh...
SharedPreferences的四種模式
開發應用需要儲存一些配置引數,如果是window軟體通常我們會採用ini檔案進行儲存,如果是j2se應用,我們會採用properties屬性檔案進行儲存。如果是android應用,我們最適合採用sharedpreferences儲存資料,它是乙個輕量級的儲存類,特別適合用於儲存軟體配置引數。有兩種方...
this的四種用法
js 中的this是比較難理解的。這裡將介紹this的具體用法。主要是下面的四種方法 1.作為物件的方法 2.作為普通函式中 3.作為構造函式呼叫 一 作為物件的方法使用,this指向這個物件 for example var adou a 1,getadou function console.log...