Spring-使用存储过程时使用simplejdbccall进行批处理更新 [英] Spring - Batch update using simplejdbccall while using Stored Procedure
本文介绍了Spring-使用存储过程时使用simplejdbccall进行批处理更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用spring jdbc模板,使用存储过程创建记录
I am using spring jdbc template, to create record using stored procedure
public Long create(City $obj) {
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(getJdbcTemplate().getDataSource()).withProcedureName(SP_ADD_UPDATE);
jdbcCall.declareParameters(new SqlOutParameter(ConstantUtil.RETUR_VAL, OracleTypes.BIGINT));
Map<String, Object> jdbcCallResult = jdbcCall.execute(new MapSqlParameterSource(populateParams($obj)));
return (Long) jdbcCallResult.get(ConstantUtil.RETUR_VAL);
}
参数
private static Map<String, Object> populateParams(City $obj) {
Map<String, Object> _params = new HashMap<String, Object>();
_params.put("CITYID", $obj.getCityId());
_params.put("CITYNAME", $obj.getCityName());
_params.put("USERID", $obj.getCurUser());
return _params;
}
如何在使用存储过程的同时使用simpleJdbcCall批量更新?
How can we batch update using simpleJdbcCall while using stored procedure ?
推荐答案
我找到了使用jdbcTemplate的解决方案:
I found a solution using jdbcTemplate:
public int insertBatch(final List<ExperimentUser> usersByExperiment)
throws Exception {
int[] insertedRows = getJdbcTemplate().batchUpdate("call myschema.myProc(?,?)",
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i)
throws SQLException {
ExperimentUser experimentUser = usersByExperiment
.get(i);
ps.setInt(1, experimentUser.getExperimentId());
ps.setString(2, experimentUser.getUniqueCode());
}
@Override
public int getBatchSize() {
return usersByExperiment.size();
}
});
return insertedRows.length;
}
这篇关于Spring-使用存储过程时使用simplejdbccall进行批处理更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文