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

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

Description

get Array

License

Open Source License

Declaration

public static <T> T[] getArray(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;

public class Main {
    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;
        }//from   ww w .  j a v a 2  s.  c o  m
        @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. getAllColumnNames(ResultSet rs)
  2. getAllColumnNamesFromResultSet(ResultSet set)
  3. getAllData(ResultSet rs)
  4. getAllRow(ResultSet rs)
  5. getAllValueMaps(ResultSet input)
  6. getArray(ResultSet rs, int index)
  7. getArray(ResultSet rs, String columnName, Class cls)
  8. getArrayAsSet(ResultSet rs, String columnLabel)
  9. getArrayFromResultSet(ResultSet rs, String field)