Java SQL ResultSet Read getArrayFromResultSet(ResultSet rs, String field)

Here you can find the source of getArrayFromResultSet(ResultSet rs, String field)

Description

Returns a string list corresponding to the given field on the given ResultSet.

License

Apache License

Parameter

Parameter Description
rs ResultSet
field Field we want to obtain the value from

Return

Long value if the field exists and can be parsed to Long. Null otherwise.

Declaration

public static List<String> getArrayFromResultSet(ResultSet rs, String field) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Array;

import java.sql.ResultSet;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**//from   w  ww.ja  v  a  2 s . co m
     * Returns a string list corresponding to the given field on the given
     * ResultSet. If the value cannot be parsed to an array, or does not exist, it
     * returns an empty value.
     * 
     * @param rs
     *            ResultSet
     * @param field
     *            Field we want to obtain the value from
     * @return Long value if the field exists and can be parsed to Long. Null otherwise.
     */
    public static List<String> getArrayFromResultSet(ResultSet rs, String field) {

        List<String> result;

        try {
            Array arrayChunks = rs.getArray(field);
            String[] chunks = (String[]) arrayChunks.getArray();
            result = Arrays.asList(chunks);

            if (result.contains(null)) {
                result = new ArrayList<String>();
            }
        } catch (Exception e) {
            result = new ArrayList<String>();
        }

        return result;
    }
}

Related

  1. getAllValueMaps(ResultSet input)
  2. getArray(ResultSet resultSet, String columnLabel, Class clazz)
  3. getArray(ResultSet rs, int index)
  4. getArray(ResultSet rs, String columnName, Class cls)
  5. getArrayAsSet(ResultSet rs, String columnLabel)
  6. getAsString(ResultSet res, String field)
  7. getBestRowId(String schema, String tableName, int scope, String nullable, ResultSet[] rs)
  8. getBigInteger(ResultSet resultSet, int columnIndex)
  9. getBigIntegerFromResultSet(ResultSet rs, String db_name)