Here you can find the source of getDate(Object value, int columnType)
public static java.sql.Date getDate(Object value, int columnType) throws Exception
//package com.java2s; //License from project: Open Source License import java.text.*; public class Main { public static java.sql.Date getDate(Object value, int columnType) throws Exception { // check for null if (value == null) { return null; }/*from w ww . ja v a2 s . c o m*/ /* * The object coming back from the db could be a date, a timestamp, or * a char field variety. If it's a date type return it, a timestamp * we turn into a long and then into a date, char strings we try to * parse. */ switch (columnType) { case java.sql.Types.DATE: { long sec = ((java.sql.Date) value).getTime(); return new java.sql.Date(sec); } case java.sql.Types.TIMESTAMP: { long sec = ((java.sql.Timestamp) value).getTime(); return new java.sql.Date(sec); } case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.NCHAR: case java.sql.Types.NVARCHAR: case java.sql.Types.LONGNVARCHAR: { try { DateFormat df = DateFormat.getDateInstance(); return ((java.sql.Date) (df.parse(value.toString()))); } catch (ParseException ex) { throw new Exception("date conversion failed. (" + value.toString().trim() + "/" + columnType + ")"); } } default: { throw new Exception("date conversion failed. (" + value.toString().trim() + "/" + columnType + ")"); } } } public static java.sql.Time getTime(Object value, int columnType) throws Exception { // check for null if (value == null) { return null; } /* * The object coming back from the db could be a date, a timestamp, or * a char field variety. If it's a date type return it, a timestamp * we turn into a long and then into a date, char strings we try to * parse. */ switch (columnType) { case java.sql.Types.TIME: { return (java.sql.Time) value; } case java.sql.Types.TIMESTAMP: { long sec = ((java.sql.Timestamp) value).getTime(); return new java.sql.Time(sec); } case java.sql.Types.CHAR: case java.sql.Types.VARCHAR: case java.sql.Types.LONGVARCHAR: case java.sql.Types.NCHAR: case java.sql.Types.NVARCHAR: case java.sql.Types.LONGNVARCHAR: { try { DateFormat df = DateFormat.getDateInstance(); return ((java.sql.Time) (df.parse(value.toString()))); } catch (ParseException ex) { throw new Exception("time conversion failed. (" + value.toString().trim() + "/" + columnType + ")"); } } default: { throw new Exception("time conversion failed. (" + value.toString().trim() + "/" + columnType + ")"); } } } }