@ Override public int [ ] executeBatch ( ) throws SQLException { checkClosed ( ) ; closeCurrentResult ( ) ; if ( batch == null || batch . size ( ) == 0 ) { return new int [ 0 ] ; } int [ ] updateCounts = new int [ batch . size ( ) ] ; // keep a running total of update counts int runningUpdateCount = 0 ; int i = 0 ; try { for ( ; i < batch . size ( ) ; i ++ ) { setCurrentResult ( null , ( int ) batch . get ( i ) . execute ( sourceConnection . NativeConnection , this . m_timeout , sourceConnection . queryTimeOutUnit ) [ 0 ] . fetchRow ( 0 ) . getLong ( 0 ) ) ; updateCounts [ i ] = this . lastUpdateCount ; runningUpdateCount += this . lastUpdateCount ; } } catch ( SQLException x ) { updateCounts [ i ] = EXECUTE_FAILED ; throw new BatchUpdateException ( Arrays . copyOf ( updateCounts , i + 1 ) , x ) ; } finally { clearBatch ( ) ; } // replace the update count from the last statement with the update count // from the last batch. this . lastUpdateCount = runningUpdateCount ; return updateCounts ; }
Submits a batch of commands to the database for execution and if all commands execute successfully returns an array of update counts .