Two different prepared statements in one single batch

前端 未结 4 754
梦毁少年i
梦毁少年i 2020-12-03 01:42

I want to send two different prepared statements in one single batch.

Currently I am doing this in two as you can see in the commented lines and it works,

4条回答
  •  既然无缘
    2020-12-03 02:23

    You can try execute the two statement is a single transaction, like this:

    connection.setAutoCommit(false);
    try {
        stmt1.execute();
        stmt2.execute();
        connection.commit();
    } catch (Exception ex) {
        connection.rollback();
    }
    

    The issue is that addBatch works on a single prepared statement, see this is how you can use multiple sql statements with addBatch.

提交回复
热议问题