SpringJDBC更新数据库的代码(批量操作)

1.批量更新

@Override

@Transactional(propagation=Propagation.REQUIRED)

public int[] insertFc(FilingFCSegmentCorrection fc,List<String> ruleCds) {

final List<MapSqlParameterSource> list=new ArrayList<MapSqlParameterSource>();

for(final String ruleCd:ruleCds){

final MapSqlParameterSource mapSql=new MapSqlParameterSource();

mapSql.addValue("inYr",fc.getInEffYr());

mapSql.addValue("carryCd",fc.getCarrierCode());

mapSql.addValue("tariffCd",fc.getRuleTariffCode());

mapSql.addValue("seqCd",fc.getSeqNo());

mapSql.addValue("zoneCd",fc.getZoneNO());

mapSql.addValue("ruleCd",ruleCd);

list.add(mapSql);

}

MapSqlParameterSource[] params=list.toArray(new MapSqlParameterSource[list.size()] );

 

return nameJdbcTemplate.batchUpdate(insertFCs,params);

}

 

2.删除

@Override

@Transactional(propagation = Propagation.REQUIRED)

public boolean deleteDDCData(final WorkUnitKeyInfo wuKeyInfo,

final FilingGroup flgGrp, final List<String> ruleCodeList) {

final MapSqlParameterSource msps = new MapSqlParameterSource();

msps.addValue(DDSConstants.CARRIER_CODE, flgGrp.getCarrier());

msps.addValue(DDSConstants.RULE_TARIFF_CODE, flgGrp.getRulesTariff());

msps.addValue(FilingConstants.RULECDLIST, ruleCodeList);

msps.addValue(DDSConstants.WORK_UNIT_OWN_ORG_CD, wuKeyInfo.getWuOwnOrgCode());

msps.addValue(DDSConstants.WORK_UNIT_CRTE_DT, wuKeyInfo.getWuCreateDt());

msps.addValue(DDSConstants.WORK_UNIT_ID_NO, wuKeyInfo.getWuIdNo());

 

final boolean ddcTextStatus = namedJdbcTemplate.update(

sqlDelDDCText, msps)>0;

 

final boolean ddcStatus = namedJdbcTemplate.update(

sqlDelDDC, msps) > 0;

 

return (ddcTextStatus && ddcStatus);

}

其中MapSqlParameterSource可换成HashMap

 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。