Here you can find the source of getNullableInt(ResultSet resultSet, String column, int fallback)
Parameter | Description |
---|---|
resultSet | to read from |
column | the column whose value is requested |
fallback | the fallback value |
Parameter | Description |
---|---|
SQLException | an exception |
public static int getNullableInt(ResultSet resultSet, String column, int fallback) throws SQLException
//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; } }