Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does executeBatch() also clear the list of commands?

The documentation of Statement.executeBatch() is not clear on this, but I assume that calling it will empty the Statement object's current list of SQL commands in the same way as clearBatch() does. I'm also assuming the same is true for PreparedStatement.

I suppose it is possible to continue using the Statement after calling Statement.executeBatch(), i.e. add another batch of commands and execute them.

like image 454
Roland Avatar asked Jan 01 '23 13:01

Roland


1 Answers

Although not explicitly mentioned in the API documentation of executeBatch, the behaviour is specified by the JDBC 4.3 Specification in section 14.1.2 Successful Execution:

The statement's batch is reset to empty once executeBatch returns.

Although this is specified in a section called 'Successful Execution', it is also the intended behaviour for unsuccessful execution.

In short, when you call executeBatch() the current batch of statements is submitted to the database server and cleared.

like image 107
Mark Rotteveel Avatar answered Jan 11 '23 22:01

Mark Rotteveel