For clarification: I know that it's the right thing to create the PreparedStatement outside the loop. I've asked this question just out of curiosity.
Let's assume that I'm creating a PreparedStatement inside a loop with always the same SQL query.
final String sql = "INSERT INTO ...";
while (condition) {
...
PreparedStatement statement = connection.prepareStatement(sql);
// Fill values of the prepared statement
// Execute statement
...
}
Is this useless since the PreparedStatement object is always created anew? Or does the underlying database recognise that it's always the same SQL query with which the PreparedStatement is created and reuses it?