Java SQL ResultSet Read getCalendar(ResultSet resultSet, String columnName)

Here you can find the source of getCalendar(ResultSet resultSet, String columnName)

Description

Transforms a given column from the java.sql.ResultSet from a java.sql.Timestamp to a java.util.Calendar.

License

Open Source License

Parameter

Parameter Description
resultSet a parameter
columnName a parameter

Exception

Parameter Description
SQLException an exception

Return

java.util.Calendar

Declaration

public static Calendar getCalendar(ResultSet resultSet, String columnName) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from w w  w  .j  av a2  s .c o  m*/
*  Adito
*
*  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
*  This program is free software; you can redistribute it and/or
*  modify it under the terms of the GNU General Public License
*  as published by the Free Software Foundation; either version 2 of
*  the License, or (at your option) any later version.
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public
*  License along with this program; if not, write to the Free Software
*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

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

import java.sql.Timestamp;

import java.util.Calendar;

public class Main {
    /**
     * Transforms a given column from the java.sql.ResultSet from a
     * java.sql.Timestamp to a java.util.Calendar.
     * 
     * @param resultSet
     * @param columnName
     * @return java.util.Calendar
     * @throws SQLException
     */
    public static Calendar getCalendar(ResultSet resultSet, String columnName) throws SQLException {
        return getCalendar(resultSet.getTimestamp(columnName));
    }

    /**
     * Transforms the supplied java.sql.Timestamp into a java.util.Calendar.
     * 
     * @param timestamp
     * @return java.util.Calendar
     */
    public static Calendar getCalendar(Timestamp timestamp) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timestamp == null ? System.currentTimeMillis() : timestamp.getTime());
        return calendar;
    }
}

Related

  1. getAsString(ResultSet res, String field)
  2. getBestRowId(String schema, String tableName, int scope, String nullable, ResultSet[] rs)
  3. getBigInteger(ResultSet resultSet, int columnIndex)
  4. getBigIntegerFromResultSet(ResultSet rs, String db_name)
  5. getBigObject(ResultSet set, int columnIndex)
  6. getCharacterStream(ResultSet resultSet, String columnName)
  7. getChunkDelimiters(ResultSet rs, int tsColumnIndex, int chunkSize)
  8. getClassName(ResultSetMetaData meta, int index)
  9. getCountFromResultSet(ResultSet rs)