1

I have following JDBC code:

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;
        }

And I would like 2 prepared statements to be part of one JDBC transaction. I am wondering whether order at which they are created will be the execution order of SQL statements: delete first and inserts - after.

4

1 に答える 1

4

それらは上から下に実行されるため、実行した順序で、削除が最初に実行され、挿入がその後に実行されます。

于 2013-09-17T21:39:20.050 に答える