Java SQL ResultSet String Read getStringList(ResultSet resultSet, String columnName)

Here you can find the source of getStringList(ResultSet resultSet, String columnName)

Description

Returns a list of string values using a given SQL result set and column name.

License

Open Source License

Parameter

Parameter Description
resultSet - Result set.
columnName - Column name.

Return

List - Column values.

Declaration

public static List<String> getStringList(ResultSet resultSet, String columnName) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from ww w .  j  av a  2  s .c o m*/
 * Copyright (C) 2015 Bryan W. Snipes
 * 
 * This file is part of the JDistil web application framework.
 * 
 * JDistil is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JDistil is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDistil.  If not, see <http://www.gnu.org/licenses/>.
 */

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
      Returns a list of string values using a given SQL result set and column name.
      @param resultSet - Result set.
      @param columnName - Column name.
      @return List - Column values.
    */
    public static List<String> getStringList(ResultSet resultSet, String columnName) throws SQLException {

        // Initialize return value
        List<String> values = null;

        if (resultSet != null && columnName != null) {

            // Create values list
            values = new ArrayList<String>();

            // Populate list
            while (resultSet.next()) {
                values.add(getString(resultSet, columnName));
            }
        }

        return values;
    }

    /**
      Returns a string value using a given SQL result set and column name.
      @param resultSet - Result set.
      @param columnName - Column name.
      @return String - Column value.
    */
    public static String getString(ResultSet resultSet, String columnName) throws SQLException {

        // Initialize return value
        String value = null;

        if (resultSet != null && columnName != null) {
            value = resultSet.getString(columnName);
        }

        return value;
    }
}

Related

  1. getString(ResultSet rs, String columnName)
  2. getString(ResultSet rs, String name)
  3. getString(ResultSet rs, String name, String ifnull)
  4. getStringChunks(ResultSet rs, int colIndex, StringBuffer buf)
  5. getStringFromResultSetEmptyIsNull(ResultSet rset, String fieldName)
  6. getStringSuppressSQLException(final ResultSet rs, final String columnLabel)
  7. getStringUTF8(ResultSet rs, String which)
  8. getStringValue(final ResultSet rs, final int index)
  9. getTrimmedStringToUpperCase(ResultSet rs, String columnLabel)