Java SQL ResultSet Read readDate(ResultSet result, int index)

Here you can find the source of readDate(ResultSet result, int index)

Description

Read a long from the result set, and convert to a null (if 0) or a Date.

License

Apache License

Parameter

Parameter Description
results The result set.
index The index.

Exception

Parameter Description
SQLException an exception

Return

The Date or null.

Declaration

public static Date readDate(ResultSet result, int index) throws SQLException 

Method Source Code

//package com.java2s;
/**********************************************************************************
 * $URL$//from  ww  w. ja v a2  s . c  om
 * $Id$
 ***********************************************************************************
 *
 * Copyright (c) 2007, 2008 The Regents of the University of Michigan & Foothill College, ETUDES Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **********************************************************************************/

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

import java.util.Date;

public class Main {
    /**
     * Read a long from the result set, and convert to a null (if 0) or a Date.
     * 
     * @param results
     *        The result set.
     * @param index
     *        The index.
     * @return The Date or null.
     * @throws SQLException
     */
    public static Date readDate(ResultSet result, int index) throws SQLException {
        long time = result.getLong(index);
        if (time == 0)
            return null;
        return new Date(time);
    }
}

Related

  1. getValue4Type(ResultSet rs, String column, Class typeClass)
  2. getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index)
  3. getValueFromResultSet(int index, final ResultSet resultSet, final Class type)
  4. readBitBoolean(ResultSet result, int index)
  5. readBytes(ResultSet rs, int pos)
  6. readMap(final ResultSet rs)
  7. readObject(java.sql.ResultSet resultSet, int index)
  8. readResults(ResultSet resultSet)
  9. wasNull(ResultSet rs, T value)