Java SQL ResultSet Read getArray(ResultSet rs, int index)

Here you can find the source of getArray(ResultSet rs, int index)

Description

get Array

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> List<T> getArray(ResultSet rs, int index) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Array;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.LinkedList;
import java.util.List;

import java.util.function.Function;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> List<T> getArray(ResultSet rs, int index) throws SQLException {
        List<T> ret = new LinkedList<T>();
        Array value = rs.getArray(index);
        if (value != null) {
            for (T e : (T[]) value.getArray()) {
                ret.add(e);//  w ww .  ja v  a2 s . com
            }
        }
        return ret;
    }

    @SuppressWarnings("unchecked")
    public static <T, U> List<U> getArray(ResultSet rs, int index, Function<T, U> mapper) throws SQLException {
        List<U> ret = new LinkedList<U>();
        Array value = rs.getArray(index);
        if (value != null) {
            for (T e : (T[]) value.getArray()) {
                ret.add(mapper.apply(e));
            }
        }
        return ret;
    }
}

Related

  1. getAllColumnNamesFromResultSet(ResultSet set)
  2. getAllData(ResultSet rs)
  3. getAllRow(ResultSet rs)
  4. getAllValueMaps(ResultSet input)
  5. getArray(ResultSet resultSet, String columnLabel, Class clazz)
  6. getArray(ResultSet rs, String columnName, Class cls)
  7. getArrayAsSet(ResultSet rs, String columnLabel)
  8. getArrayFromResultSet(ResultSet rs, String field)
  9. getAsString(ResultSet res, String field)