2017-10-21 292 views
0

我使用了Spring JDBC模板,使用存儲過程春天 - 使用SimpleJdbcCall時,同時使用存儲過程

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時同時使用

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); 
} 

PARAMS創造紀錄批量更新存儲過程?

回答

0

我發現使用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; 
    }  
相關問題