Here you can find the source of getDate(ResultSet rs, String colName)
Parameter | Description |
---|---|
rs | the result set |
colName | the coloumn containg the date |
Parameter | Description |
---|---|
SQLException | an exception |
public final static Date getDate(ResultSet rs, String colName) throws SQLException
//package com.java2s; /******************************************************************************* * This file is part of ISPyB.//w w w . j a v a 2 s. c om * * ISPyB is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ISPyB 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with ISPyB. If not, see <http://www.gnu.org/licenses/>. * * Contributors : S. Delageniere, R. Leal, L. Launer, K. Levik, S. Veyrier, P. Brenchereau, M. Bodin, A. De Maria Antolinos ******************************************************************************/ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; public class Main { /** * Returns a date value from a JDBC result set containing only the day part. * * @param rs * the result set * @param colName * the coloumn containg the date * @return the date value with time part set to 00:00:00,000 * @throws SQLException */ public final static Date getDate(ResultSet rs, String colName) throws SQLException { if (colName == null || colName.length() == 0 || rs == null) { throw new IllegalArgumentException("getDate: one or more parameters are null"); } Date res = convertSQLDate2Date(rs.getDate(colName)); if (rs.wasNull()) { return null; } return res; } /** * Converts a java.sql.Date object to a java.util.Date object. * * @param date * the java.sql.Date object * @return a java.util.Date object */ public static final Date convertSQLDate2Date(java.sql.Date date) { if (date == null) { return null; } return new Date(date.getTime()); } }