Java SQL ResultSet Read getList(ResultSet resultSet, String columnLabel, Class clazz)

Here you can find the source of getList(ResultSet resultSet, String columnLabel, Class clazz)

Description

get List

License

Open Source License

Declaration

public static <T> List<T> getList(ResultSet resultSet, String columnLabel, Class<T> clazz) throws SQLException 

Method Source Code


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

import java.lang.reflect.Array;

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

import java.util.Arrays;

import java.util.List;

public class Main {
    public static <T> List<T> getList(ResultSet resultSet, String columnLabel, Class<T> clazz) throws SQLException {
        return Arrays.asList(getArray(resultSet, columnLabel, clazz));
    }/*from  w  w  w.j  ava2  s .  c  om*/

    public static <T> List<T> getList(ResultSet resultSet, int columnIndex, Class<T> clazz) throws SQLException {
        return Arrays.asList(getArray(resultSet, columnIndex, clazz));
    }

    public static <T> T[] getArray(ResultSet resultSet, String columnLabel, Class<T> clazz) throws SQLException {
        @SuppressWarnings("unchecked")
        T[] array = (T[]) resultSet.getArray(columnLabel).getArray();
        if (array != null) {
            return array;
        }
        @SuppressWarnings("unchecked")
        T[] empty = (T[]) Array.newInstance(clazz, 0);
        return empty;
    }

    public static <T> T[] getArray(ResultSet resultSet, int columnIndex, Class<T> clazz) throws SQLException {
        @SuppressWarnings("unchecked")
        T[] array = (T[]) resultSet.getArray(columnIndex).getArray();
        if (array != null) {
            return array;
        }
        @SuppressWarnings("unchecked")
        T[] empty = (T[]) Array.newInstance(clazz, 0);
        return empty;
    }
}

Related

  1. getHighPrecisionString(ResultSet rs, int ix, int sql_type)
  2. getHtmlRows(ResultSet results)
  3. getHtmlTable(ResultSet results)
  4. getId(ResultSet key)
  5. getIndex(ResultSet rs, int index)
  6. getList(ResultSet rs)
  7. getListFromRS(Class clazz, ResultSet rs)
  8. getListMapFromResultSet(ResultSet rs)
  9. getLocalDate(ResultSet res, String name)