Java SQL ResultSet Double Read getDoubleList(ResultSet resultSet, String columnName)

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

Description

Returns a list of double 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<Double> getDoubleList(ResultSet resultSet, String columnName) throws SQLException 

Method Source Code

//package com.java2s;
/*//from  w w  w  .ja v 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 double 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<Double> getDoubleList(ResultSet resultSet, String columnName) throws SQLException {

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

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

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

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

        return values;
    }

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

        // Initialize return value
        Double value = null;

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

            // Get column value
            double columnValue = resultSet.getDouble(columnName);

            // Check for null value
            if (!resultSet.wasNull()) {
                value = new Double(columnValue);
            }
        }

        return value;
    }
}

Related

  1. getDouble(ResultSet rs, int index)
  2. getDouble(ResultSet rs, String colName)
  3. getDouble(ResultSet rs, String column)
  4. getDouble(ResultSet rs, String columnName)
  5. getDouble2(ResultSet rs, int index)
  6. getDoubleNotZero(ResultSet rs, String columnLabel)
  7. getDoubleOrNanFromResultSet(ResultSet rs, int index)
  8. getDoubleOrNull(ResultSet rs, String columnName)
  9. getDoubleValue(ResultSet resultSet, int columnIndex)