以下の内容はhttps://wrongwrong163377.hatenablog.com/entry/2018/12/27/003000より取得しました。


【JDBC】SimpleJdbcInsertで複数の要素を一気にInsertする

BeanPropertySqlParameterSourceの配列を作ってSimpleJdbcInsert#executeBatchに入れるとできます。

//配列を作る関数
private BeanPropertySqlParameterSource[] makeParamArray(List entities){
    BeanPropertySqlParameterSource[] sources = new BeanPropertySqlParameterSource[entities.size()];
    for(int i = 0; i < entities.size(); i++){
        sources[i] = new BeanPropertySqlParameterSource(entities.get(i));
    }
    return sources;
}

//インサート例
public void insertテーブル名(List<[Entity]> entities) {
    SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(jdbcTemplate).withTableName("[テーブル名]");
    jdbcInsert.executeBatch(makeParamArray(entities));
}



以上の内容はhttps://wrongwrong163377.hatenablog.com/entry/2018/12/27/003000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14