Skip to content

Latest commit

 

History

History
27 lines (22 loc) · 780 Bytes

BulkInsert.md

File metadata and controls

27 lines (22 loc) · 780 Bytes

Jdbc를 통한 Bulk Insert

@Repository
@RequiredArgsConstructor
public class someJdbcRepository {

    private final JdbcTemplate jdbcTemplate;

    public int[] bulkInsert(List<SomeEntity> someEntities) {
        return this.jdbcTemplate.batchUpdate(
            "insert into some_table (some_value) values (?)",
            new BatchPreparedStatement() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    SomeEntity someEntity = someEntities.get(i);
                    ps.setLong(1, someEntity.getSomeValue(i));
                }

                @Override
                public int getBatchSize() {
                    return someEntities.size();
            });
    }
}