springJDBC的两种查询数据库方法

1.RowCallbackHandler

@Override

public List<FilingFCSegmentCorrection> retrieveFCSegmentCorrections(Integer year,String ruleTariffCode,

String carrierCode) {

final Map<String,Object> sqlParamaterMap= new HashMap<String,Object>();

sqlParamaterMap.putAll(setTCToParaMap(ruleTariffCode,carrierCode));

sqlParamaterMap.put("year",year);

final List<FilingFCSegmentCorrection> fcList=new ArrayList<FilingFCSegmentCorrection>();

nameJdbcTemplate.query(sqlGetFCs,sqlParamaterMap,new RowCallbackHandler() {

 

@Override

public void processRow(ResultSet rs) throws SQLException {

final FilingFCSegmentCorrection fc=new FilingFCSegmentCorrection();

fc.setCarrierCode(rs.getString("CXR_CD"));

fc.setRuleTariffCode(rs.getString("RULE_TAR_CD"));

fc.setInEffYr(rs.getInt("IN_EFF_YR"));

fc.setRuleCode(rs.getString("RULE_CD"));

fc.setSeqNo((Integer) rs.getObject("SEQ_NO"));

fc.setZoneNO(rs.getInt("ZONE_NO"));

fcList.add(fc);

}

});

return fcList;

}

 

2.RowMapper

@Override

public List<FilingFCSegmentCorrection> retrieveFCSegmentCorrections(Integer year,String ruleTariffCode,

String carrierCode) {

final Map<String ,Object> sqlParamaterMap=setTCToParaMap(ruleTariffCode,carrierCode);

sqlParamaterMap.put("year",year);

final RowMapper<FilingFCSegmentCorrection> rowMapper=new RowMapper<FilingFCSegmentCorrection>() {

 

@Override

public FilingFCSegmentCorrection mapRow(ResultSet result, int arg1) throws SQLException {

final FilingFCSegmentCorrection fc=new FilingFCSegmentCorrection();

setCommonFieldsForFc(result,fc);

fc.setSeqNo((Integer) result.getObject("SEQ_NO"));

fc.setZoneNO(result.getInt("ZONE_NO"));

return fc;

}

};

return nameJdbcTemplate.query(sqlGetFCs,sqlParamaterMap,rowMapper);

}

 

附dao类:

public

abstract class DDSDAO {

@Autowired

protected transient NamedParameterJdbcTemplate nameJdbcTemplate;

 

protected JdbcTemplate getJdbcTemplate() {

return (JdbcTemplate) this.nameJdbcTemplate.getJdbcOperations();

}

 

}

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