executeBatch() 是否也清除命令列表?

Does executeBatch() also clear the list of commands?

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 的文档。

我想可以在调用Statement.executeBatch()后继续使用Statement,即添加另一批命令并执行它们。

虽然 executeBatch 的 API 文档中未明确提及,但 14.1.2 成功执行[=21] 部分中的 JDBC 4.3 Specification 指定了行为=]:

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

虽然这在名为 'Successful Execution' 的部分中指定,但它也是执行不成功的预期行为。

简而言之,当您调用executeBatch()时,当前批次的语句被提交到数据库服务器并被清除。