To clarify: I know what is right to create PreparedStatementoutside the loop. I asked this question only out of curiosity.
Suppose I create PreparedStatementinside a loop with always the same SQL query.
final String sql = "INSERT INTO ...";
while (condition) {
...
PreparedStatement statement = connection.prepareStatement(sql);
...
}
Is it really useless, since the object is PreparedStatementalways recreated? Or does the underlying database recognize that it is always the same SQL query that creates PreparedStatementand reuses it?
user321068
source
share