public static int executeBatchUpdate(final Connection conn, final String sql, final List<?> parametersListList, final int batchSize) throws SQLException {
        N.checkArgNotNull(conn);
        N.checkArgNotNull(sql);
        N.checkArgPositive(batchSize, "batchSize");

        if (N.isNullOrEmpty(parametersListList)) {
            return 0;
        }

        final NamedSQL namedSQL = NamedSQL.parse(sql);
        PreparedStatement stmt = null;

        try {
            stmt = conn.prepareStatement(namedSQL.getPureSQL());

            int res = 0;
            int idx = 0;

            for (Object parameters : parametersListList) {
                SQLExecutor.StatementSetter.DEFAULT.setParameters(namedSQL, stmt, N.asArray(parameters));
                stmt.addBatch();

                if (++idx % batchSize == 0) {
                    res += stmt.executeUpdate();
                    stmt.clearBatch();
                }
            }

            if (idx % batchSize != 0) {
                res += stmt.executeUpdate();
                stmt.clearBatch();
            }

            return res;
        } finally {
            JdbcUtil.closeQuietly(stmt);
        }
    }
public static int executeBatchUpdate ( final Connection conn , final String sql , final List < ? > parametersListList , final int batchSize ) throws SQLException { N . checkArgNotNull ( conn ) ; N . checkArgNotNull ( sql ) ; N . checkArgPositive ( batchSize , "batchSize" ) ; if ( N . isNullOrEmpty ( parametersListList ) ) { return 0 ; } final NamedSQL namedSQL = NamedSQL . parse ( sql ) ; PreparedStatement stmt = null ; try { stmt = conn . prepareStatement ( namedSQL . getPureSQL ( ) ) ; int res = 0 ; int idx = 0 ; for ( Object parameters : parametersListList ) { SQLExecutor . StatementSetter . DEFAULT . setParameters ( namedSQL , stmt , N . asArray ( parameters ) ) ; stmt . addBatch ( ) ; if ( ++ idx % batchSize == 0 ) { res += stmt . executeUpdate ( ) ; stmt . clearBatch ( ) ; } } if ( idx % batchSize != 0 ) { res += stmt . executeUpdate ( ) ; stmt . clearBatch ( ) ; } return res ; } finally { JdbcUtil . closeQuietly ( stmt ) ; } }
@param conn
@param sql
@param parametersListList
@param batchSize.
@return
@throws SQLException