Java SQL ResultSet Int Read getInteger(ResultSet resultSet, String columnName)

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

Description

Returns an integer value using a given SQL result set and column name.

License

Open Source License

Parameter

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

Return

Integer - Column value.

Declaration

public static Integer getInteger(ResultSet resultSet, String columnName) throws SQLException 

Method Source Code

//package com.java2s;
/*/*  ww w  . j a va  2s  .  com*/
 * 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;

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

        // Initialize return value
        Integer value = null;

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

            // Get column value
            int columnValue = resultSet.getInt(columnName);

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

        return value;
    }
}

Related

  1. getInt(ResultSet results, int parameterIndex)
  2. getInt(ResultSet rs, int columnIndex)
  3. getInt(ResultSet rs, String column)
  4. getInt(ResultSet rs, String columnName)
  5. getInteger(final ResultSet rs, final String field)
  6. getInteger(ResultSet rs, String colName)
  7. getInteger(ResultSet rs, String column)
  8. getInteger(ResultSet rs, String columnName)
  9. getInteger(ResultSet rs, String strColName)