Skip to content

Commit

Permalink
feat: batch sql queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Nov 14, 2023
1 parent 379ca89 commit 3466046
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/main/java/com/github/mjeanroy/dbunit/core/jdbc/JdbcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,17 @@ static <T> List<T> executeQuery(Connection connection, String query, ResultSetMa
}

static void executeUpdates(Connection connection, Collection<String> queries) {
log.debug("Executing queries: {}", queries);
for (String query : queries) {
executeUpdate(connection, query);
}
}

static void executeUpdate(Connection connection, String query) {
log.debug("Executing update: {}", query);
log.debug("Executing batched queries: {}", queries);
try (Statement statement = connection.createStatement()) {
statement.executeUpdate(query);
for (String query : queries) {
log.debug("Adding batched query: {}", query);
statement.addBatch(query);
}

statement.executeBatch();
}
catch (SQLException ex) {
throw new JdbcException("Cannot execute query: " + query, ex);
throw new JdbcException("Cannot execute queries: " + queries, ex);
}
}

Expand Down

0 comments on commit 3466046

Please sign in to comment.