Skip to content

Instantly share code, notes, and snippets.

@jerolba
Created August 26, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerolba/0c060b1f1e245291cbd709adfd7b69cf to your computer and use it in GitHub Desktop.
Save jerolba/0c060b1f1e245291cbd709adfd7b69cf to your computer and use it in GitHub Desktop.
JDBC in batches of 1000 records
connection.setAutoCommit(false);
try (PreparedStatement pstmt = connection.prepareStatement(TripEntityInsert.INSERT)) {
int cont = 0;
Iterator<TripEntity> iterator = trips.iterator();
while (iterator.hasNext()) {
TripEntity entity = iterator.next();
tripInsert.setParameters(pstmt, entity);
pstmt.addBatch();
cont++;
if (cont % batchSize == 0) {
pstmt.executeBatch();
connection.commit();
}
}
connection.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment