Executing a batch of SQL queries instead of individual queries improves performance by reducing communication overhead with the database.
Batching SQL statements is beneficial in common situations where a SQL statement is executed within a loop. In such cases, adding the statement to
a batch and subsequently executing it reduces the number of interactions with the database. This results in improved efficiency and faster execution
times.
The rule raises an issue when it detects a java.sql.Statement
being executed within a loop instruction, such as for
,
while
or the forEach
method of java.lang.Iterable
, java.util.Map
and
java.util.stream.Stream
.