Created
August 26, 2018 15:34
-
-
Save jerolba/fc5d792d07dabac36c96adacf6b292a7 to your computer and use it in GitHub Desktop.
JDBC a register each time in transactions of 1000 elements
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()) { | |
tripInsert.setParameters(pstmt, iterator.next()); | |
pstmt.executeUpdate(); | |
cont++; | |
if (cont % batchSize == 0) { | |
connection.commit(); | |
} | |
} | |
connection.commit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment