Java SQL ResultSet Read getResultSetDateValue(ResultSet rs, String sColumnName)

Here you can find the source of getResultSetDateValue(ResultSet rs, String sColumnName)

Description

Converts a resultset item into a java.util.Date.

License

Open Source License

Parameter

Parameter Description
rs a parameter
sColumnName a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static Date getResultSetDateValue(ResultSet rs, String sColumnName) throws Exception 

Method Source Code

//package com.java2s;
/** ***************************************************************
Util.java/*from   w  w w  .  j  a va  2s.com*/
Copyright (C) 2001  Brendon Upson 
http://www.wnc.net.au info@wnc.net.au
    
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    
 *************************************************************** */

import java.sql.ResultSet;

import java.sql.Timestamp;

import java.util.Date;

public class Main {
    /**
     * Converts a resultset item into a java.util.Date. This includes the date and time components
     * @param rs
     * @param sColumnName
     * @return
     * @throws Exception
     */
    public static Date getResultSetDateValue(ResultSet rs, String sColumnName) throws Exception {
        Timestamp ts = rs.getTimestamp(sColumnName);
        if (ts != null)
            return new Date(ts.getTime());
        return null;
    }
}

Related

  1. getResultSet(Connection conn, String query)
  2. getResultSet(Connection connection, String query)
  3. getResultSet(String sql)
  4. getResultSetColnumNames(ResultSet rs)
  5. getResultSetColumns(ResultSet rs)
  6. GetResultSetFromQuery(String command)
  7. getResultSetFromQueryAgainstDefaultConnection( String sql)
  8. getResultSetInstance(Connection conn, String sql)
  9. getResultSetMetaData(ResultSet rs)