Are the parameter values automatically cleared after executing a batch of SQL commands with a Java PreparedStatemen?

Spread the love

Question Description

I have the following code snippet:

PreparedStatement preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < 100000; i++) {
    preparedStatement.setObject(1, someValue);
    if ((i + 1) % 100 == 0) {

so I want to execute one command around 100 000 times with different values. My question is: are the parameters from the PreparedStatement cleared after each call to executeBatch() or do I have to explicitly call preparedStatement.clearParameters() after calling executeBatch() in order to make sure that there will be executed only the last 100 commands?

Practice As Follows

As I can see here:

executeBatch() calls clearBatch() in the end.

But there is no guarantee for that will be exactly the same in other implementations.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.