Created
August 26, 2018 15:35
-
-
Save jerolba/0c060b1f1e245291cbd709adfd7b69cf to your computer and use it in GitHub Desktop.
JDBC in batches of 1000 records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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