我们往往需要向数据库中插入一个List<>,这个List有时候会很大,此时如果直接循环插入数据库会重复的打开关闭数据库,这是很消耗资源的,保存一下我的解决办法:一次拼装多个sql在一起,转换成String,然后执行此sql,这样就会大大减少对数据库的操作。代码示例如下
public boolean insertTotempCommPriceList(
List
middleTempCommPriceList,int suid) {
try {
StringBuffer sql=new StringBuffer();
MiddleTempCommPrice tempCommPriceEntity=null;
sql.append("INSERT INTO wit_selection.middle_temp_spjg")
.append("(spid,spbh,hshj,lastmodifytime,supplierId) ");
sql.append("values ");
int _index=0;
for(int i=0;i
转载请注明原文地址: https://ju.6miu.com/read-1125712.html