Java SQL ResultSet Read getDbDateValue(ResultSet rs, String columnName)

Here you can find the source of getDbDateValue(ResultSet rs, String columnName)

Description

Given a ResultSet and a column name containing a [possibly null] Date, this method attempts to fetch the date from the result set.

License

Apache License

Parameter

Parameter Description
rs the result set to search
columnName the desired column name containing data of type <code>Date</code>

Return

the value, if successful; null otherwise

Declaration

public static Date getDbDateValue(ResultSet rs, String columnName) 

Method Source Code

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

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

import java.util.Date;

public class Main {
    /**//from   w  w w  .j  a  v  a2s  .co  m
     * Given a <code>ResultSet</code> and a column name containing a [possibly
     * null] <code>Date</code>, this method attempts to fetch the date from the
     * result set. If successful, the value is returned
     * as a <code>Date</code>; otherwise, null <code>Date</code> is returned.
     * @param rs the result set to search
     * @param columnName the desired column name containing data of type <code>Date</code>
     * @return the value, if successful; null otherwise
     */
    public static Date getDbDateValue(ResultSet rs, String columnName) {
        Date retVal = null;

        try {
            Object o = rs.getObject(columnName);
            if (o != null)
                retVal = (Date) o;
        } catch (SQLException e) {
            throw new RuntimeException("Unable to get result set Date value for column '" + columnName + "'");
        }

        return retVal;
    }
}

Related

  1. getClassName(ResultSetMetaData meta, int index)
  2. getCountFromResultSet(ResultSet rs)
  3. getData(final ResultSet rs)
  4. getDataDupls(ResultSet rs)
  5. getDateList(ResultSet resultSet, String columnName)
  6. getDebugData(ResultSet rs)
  7. getDuplicacy(ResultSet rs)
  8. getEntityMap(ResultSet rs, ResultSetMetaData rsmd)
  9. getEnum(Class enumClass, ResultSet rs, String columnName)