Java SQL ResultSet Read getNullableInt(ResultSet resultSet, String column, int fallback)

Here you can find the source of getNullableInt(ResultSet resultSet, String column, int fallback)

Description

Loads the value for the given column from a ResultSet .

License

Apache License

Parameter

Parameter Description
resultSet to read from
column the column whose value is requested
fallback the fallback value

Exception

Parameter Description
SQLException an exception

Return

the value in the resultSet for the column , or the fallback value if it was null

Declaration

public static int getNullableInt(ResultSet resultSet, String column, int fallback) throws SQLException 

Method Source Code


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

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

public class Main {
    /**/*from   w  w  w .  ja  v a 2  s. c  o  m*/
     * Loads the value for the given column from a {@link ResultSet}. If the value was {@code null}, a fallback
     * value is instead returned.
     *
     * @param resultSet to read from
     * @param column    the column whose value is requested
     * @param fallback  the fallback value
     * @return the value in the {@code resultSet} for the {@code column}, or the {@code fallback} value if it
     * was {@code null}
     * @throws SQLException
     */
    public static int getNullableInt(ResultSet resultSet, String column, int fallback) throws SQLException {
        int value = resultSet.getInt(column);
        return (value == 0 && resultSet.wasNull()) ? fallback : value;
    }
}

Related

  1. getMap(ResultSet rs, ResultSetMetaData metaData, int cols_len)
  2. getMetaData(ResultSet rs)
  3. getNullable(final ResultSet resultSet, final T value)
  4. getNullableBooleanFromResultSet(ResultSet rset, Enum field)
  5. getNullableByte(ResultSet resultSet, String columnLabel)
  6. getNullableLong(ResultSet rs, String columnName)
  7. getNullDate(ResultSet result, String columnName)
  8. getNumber(ResultSet rs, String name)
  9. getNumberColumns(ResultSet rs)