Java SQL ResultSet Long Read getLongFromResultSet(ResultSet rs, String field)

Here you can find the source of getLongFromResultSet(ResultSet rs, String field)

Description

Returns the Long value corresponding to the given field on the given ResultSet.

License

Apache License

Parameter

Parameter Description
rs ResultSet
field Field we want to obtain the value from

Return

Long value if the field exists and can be parsed to Long. Null otherwise.

Declaration

public static Long getLongFromResultSet(ResultSet rs, String field) 

Method Source Code

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

import java.sql.ResultSet;

public class Main {
    /**//from  w ww.ja v  a2  s  . c o m
     * Returns the Long value corresponding to the given field on the given
     * ResultSet. If the value cannot be parsed to Long, or does not exist, it
     * returns a null value.
     * 
     * @param rs
     *            ResultSet
     * @param field
     *            Field we want to obtain the value from
     * @return Long value if the field exists and can be parsed to Long. Null otherwise.
     */
    public static Long getLongFromResultSet(ResultSet rs, String field) {

        Long result = null;

        try {
            Object value = rs.getObject(field);
            if (value != null) {
                result = (Long) value;
            }
        } catch (Exception e) {
        }
        return result;
    }
}

Related

  1. getLong(ResultSet rs, String column)
  2. getLong(ResultSet rs, String columnName)
  3. getLong(ResultSet rs, String columnName)
  4. getLongDateFromResultSet(ResultSet rset, Enum field)
  5. getLongFromResultSet(ResultSet rs, String db_name)
  6. getLongList(ResultSet resultSet, String columnName)
  7. getLongOrNull(ResultSet rs, String column)
  8. getLongString(ResultSet rs, int pos)
  9. getLongValue(ResultSet resultSet, int columnIndex)