我有以下JDBC代码:
Connection conn = connectUserDataSource();
// Setting auto commit to false to execute all queries as part of transaction
conn.setAutoCommit(false);
PreparedStatement deletePreparedStatement = null;
PreparedStatement insertPreparedStatement = null;
try
{
deletePreparedStatement = conn.prepareStatement(sqlDelete);
deletePreparedStatement.setInt(1, someId);
deletePreparedStatement.executeUpdate();
insertPreparedStatement = conn.prepareStatement(sqlInsert);
for(SomeObject obj : objects)
{
insertPreparedStatement.setInt(1, obj.getId());
}
insertPreparedStatement.executeBatch();
// committing transaction
conn.commit();
transactionComplete = true;
}
我想2条准备的语句是一个JDBC事务的一部分。 我想知道,是否在其创建将SQL语句的执行顺序顺序:先删除和插入 - 后。