Java SQL ResultSet Int Read getIntegerValue(ResultSet rs, int columnIndex)

Here you can find the source of getIntegerValue(ResultSet rs, int columnIndex)

Description

Retrieves the value of the designated column in the current row of this ResultSet object as an Integer in the Java programming language.

License

Open Source License

Parameter

Parameter Description
columnIndex the first column is 1, the second is 2, ...

Exception

Parameter Description
SQLException if the columnIndex is not valid; if a database access error occurs or thismethod is called on a closed result set

Return

the column value; if the value is SQL NULL, the value returned is null

Declaration

public static Integer getIntegerValue(ResultSet rs, int columnIndex) throws SQLException 

Method Source Code

//package com.java2s;
/*//www. j  a  v  a2s .  c o  m
 * JdbcUtils.java
 *
 * Copyright (c) 1998 - 2009 BusinessTechnology, Ltd.
 * All rights reserved
 *
 * This program is the proprietary and confidential information
 * of BusinessTechnology, Ltd. and may be used and disclosed only
 * as authorized in a license agreement authorizing and
 * controlling such use and disclosure
 *
 * Millennium Business Suite Anywhere System.
 *
 */

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

public class Main {
    /**
     * Retrieves the value of the designated column in the current row of this <code>ResultSet</code>
     * object as an <code>Integer</code> in the Java programming language.
     *
     * @param columnIndex the first column is 1, the second is 2, ...
     * @return the column value; if the value is SQL <code>NULL</code>, the value returned is
     * <code>null</code>
     * @throws SQLException if the columnIndex is not valid; if a database access error occurs or this
     *                      method is called on a closed result set
     */
    public static Integer getIntegerValue(ResultSet rs, int columnIndex) throws SQLException {
        return rs.getObject(columnIndex) == null ? null : rs.getInt(columnIndex);
    }

    /**
     * Retrieves the value of the designated column in the current row of this <code>ResultSet</code>
     * object as an <code>Integer</code> in the Java programming language.
     *
     * @param columnLabel the label for the column specified with the SQL AS clause.  If the SQL AS
     *                    clause was not specified, then the label is the name of the column
     * @return the column value; if the value is SQL <code>NULL</code>, the value returned is
     * <code>null</code>
     * @throws SQLException if the columnLabel is not valid; if a database access error occurs or this
     *                      method is called on a closed result set
     */
    public static Integer getIntegerValue(ResultSet rs, String columnName) throws SQLException {
        return rs.getObject(columnName) == null ? null : rs.getInt(columnName);
    }
}

Related

  1. getIntegerFromResultSet(ResultSet rs, String db_name)
  2. getIntegerList(ResultSet resultSet, String columnName)
  3. getIntegerNotZeroNotMinValue(ResultSet rs, String columnLabel)
  4. getIntegers(ResultSet rs, String column)
  5. getIntegerValue(ResultSet resultSet, String columnName)
  6. getIntFromResultSet(ResultSet rs, String field)
  7. getIntFromResultSet(ResultSet rset, Enum field)
  8. readIntegerFromResultSet(ResultSet rs, String column)