@SuppressWarnings({ "unchecked", "rawtypes" })
    public static <E extends Exception> long importCSV(final Reader reader, long offset, final long count, final boolean skipTitle,
            final Try.Predicate<String[], E> filter, final PreparedStatement stmt, final int batchSize, final int batchInterval,
            final List<? extends Type> columnTypeList) throws UncheckedSQLException, UncheckedIOException, E {
        N.checkArgument(offset >= 0 && count >= 0, "'offset'=%s and 'count'=%s can't be negative", offset, count);
        N.checkArgument(batchSize > 0 && batchInterval >= 0, "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative", batchSize,
                batchInterval);

        long result = 0;
        final BufferedReader br = Objectory.createBufferedReader(reader);

        try {
            if (skipTitle) {
                br.readLine(); // skip the title line.
            }

            while (offset-- > 0 && br.readLine() != null) {
            }

            final Type<Object>[] columnTypes = columnTypeList.toArray(new Type[columnTypeList.size()]);
            final String[] strs = new String[columnTypeList.size()];
            String line = null;
            Type<Object> type = null;

            while (result < count && (line = br.readLine()) != null) {
                jsonParser.readString(strs, line);

                if (filter != null && filter.test(strs) == false) {
                    continue;
                }

                for (int i = 0, parameterIndex = 1, len = strs.length; i < len; i++) {
                    type = columnTypes[i];

                    if (type == null) {
                        continue;
                    }

                    type.set(stmt, parameterIndex++, (strs[i] == null) ? null : type.valueOf(strs[i]));
                }

                stmt.addBatch();

                result++;

                if ((result % batchSize) == 0) {
                    stmt.executeBatch();
                    stmt.clearBatch();

                    if (batchInterval > 0) {
                        N.sleep(batchInterval);
                    }
                }
            }

            if ((result % batchSize) > 0) {
                stmt.executeBatch();
                stmt.clearBatch();
            }
        } catch (SQLException e) {
            throw new UncheckedSQLException(e);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        } finally {
            Objectory.recycle(br);
        }

        return result;
    }
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public static < E extends Exception > long importCSV ( final Reader reader , long offset , final long count , final boolean skipTitle , final Try . Predicate < String [ ] , E > filter , final PreparedStatement stmt , final int batchSize , final int batchInterval , final List < ? extends Type > columnTypeList ) throws UncheckedSQLException , UncheckedIOException , E { N . checkArgument ( offset >= 0 && count >= 0 , "'offset'=%s and 'count'=%s can't be negative" , offset , count ) ; N . checkArgument ( batchSize > 0 && batchInterval >= 0 , "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative" , batchSize , batchInterval ) ; long result = 0 ; final BufferedReader br = Objectory . createBufferedReader ( reader ) ; try { if ( skipTitle ) { br . readLine ( ) ; } while ( offset -- > 0 && br . readLine ( ) != null ) { } final Type < Object > [ ] columnTypes = columnTypeList . toArray ( new Type [ columnTypeList . size ( ) ] ) ; final String [ ] strs = new String [ columnTypeList . size ( ) ] ; String line = null ; Type < Object > type = null ; while ( result < count && ( line = br . readLine ( ) ) != null ) { jsonParser . readString ( strs , line ) ; if ( filter != null && filter . test ( strs ) == false ) { continue ; } for ( int i = 0 , parameterIndex = 1 , len = strs . length ; i < len ; i ++ ) { type = columnTypes [ i ] ; if ( type == null ) { continue ; } type . set ( stmt , parameterIndex ++ , ( strs [ i ] == null ) ? null : type . valueOf ( strs [ i ] ) ) ; } stmt . addBatch ( ) ; result ++ ; if ( ( result % batchSize ) == 0 ) { stmt . executeBatch ( ) ; stmt . clearBatch ( ) ; if ( batchInterval > 0 ) { N . sleep ( batchInterval ) ; } } } if ( ( result % batchSize ) > 0 ) { stmt . executeBatch ( ) ; stmt . clearBatch ( ) ; } } catch ( SQLException e ) { throw new UncheckedSQLException ( e ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } finally { Objectory . recycle ( br ) ; } return result ; }
Imports the data from CSV to database.

@param reader
@param offset
@param count
@param skipTitle
@param filter
@param stmt the column order in the sql must be consistent with the column order in the CSV file.
@param batchSize
@param batchInterval
@param columnTypeList set the column type to null to skip the column in CSV.
@return