Java Utililty Methods SQL ResultSet Read

List of utility methods to do SQL ResultSet Read

Description

The list of methods to do SQL ResultSet Read are organized into topic(s).

Method

intgetNullableInt(ResultSet resultSet, String column, int fallback)
Loads the value for the given column from a ResultSet .
int value = resultSet.getInt(column);
return (value == 0 && resultSet.wasNull()) ? fallback : value;
LonggetNullableLong(ResultSet rs, String columnName)
Returns the long value of a column, or null when appropriate.
long longValue = rs.getLong(columnName);
return rs.wasNull() ? null : longValue;
DategetNullDate(ResultSet result, String columnName)
Reads date from result set.
long birthTime = result.getLong(columnName);
if (birthTime == NULL_VALUE) {
    return null;
return new Date(birthTime);
StringgetNumber(ResultSet rs, String name)
get Number
try {
    return "\"" + name + "\":" + rs.getLong(name) + "";
} catch (SQLException ex) {
    return "\"" + name + "\":\"error\"";
intgetNumberColumns(ResultSet rs)
get Number Columns
ResultSetMetaData md = rs.getMetaData();
int nCols = md.getColumnCount();
return (nCols);
intgetNumRows(ResultSet query)
get Num Rows
int numRows = 0;
try {
    if (query.last())
        numRows = query.getRow();
} catch (SQLException e) {
    e.printStackTrace();
return numRows;
...
TgetObject(ResultSet resultSet, int columnCount, Map columnLabelMap, String[] fields, String[] columnLabel, Class cls, Boolean flag)
get Object
try {
    T entity = cls.newInstance();
    if (fields != null && columnLabel != null) {
        for (int j = 0; j < fields.length; j++) {
            Object object = columnLabelMap.get(columnLabel[j]) == null ? null
                    : resultSet.getObject(columnLabel[j]);
            if (object != null) {
                String fieldName = fields[j];
...
ObjectgetObject(ResultSet rs, int columnIndex, Class type)
get Object
if (BigDecimal.class == type)
    return rs.getBigDecimal(columnIndex);
if (Blob.class == type)
    return rs.getBlob(columnIndex);
if (boolean.class == type || Boolean.class == type)
    return rs.getBoolean(columnIndex);
if (byte.class == type || Byte.class == type)
    return rs.getByte(columnIndex);
...
ObjectgetObject(ResultSet set, int columnIndex)
Get Object by special column index
Object object = null;
try {
    object = set.getObject(columnIndex);
} catch (SQLException e) {
    if (NULLDATE.equals(set.getString(columnIndex))) {
        object = null;
    } else {
        throw e;
...
ObjectgetObjectByTypeCoercion(ResultSet resultSet, int index, int dataType)
get Object By Type Coercion
switch (dataType) {
case Types.TIMESTAMP:
    return resultSet.getTimestamp(index);
case Types.CLOB:
    return resultSet.getString(index);
case Types.BLOB:
    return resultSet.getString(index);
default:
...