Java Utililty Methods SQL Date Get

List of utility methods to do SQL Date Get

Description

The list of methods to do SQL Date Get are organized into topic(s).

Method

java.sql.DategetDate(final int year, final int month, final int day)
Creates a java.sql.Date for a specified date in the UTC time zone.
final Calendar cal = new GregorianCalendar(UTC);
cal.clear();
cal.set(year, month - 1, day);
return new java.sql.Date(cal.getTimeInMillis());
TimestampgetDate(final String value)
get Date
if (value.equalsIgnoreCase("NOW"))
    return new Timestamp(Calendar.getInstance().getTime().getTime());
else
    return Timestamp.valueOf(value);
DategetDate(Map m, String key)
get Date
return (Date) m.get(key);
DategetDate(Object object)
get Date
Date date = null;
try {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm");
    SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd");
    if (object instanceof String) {
        try {
            date = format.parse((String) object);
...
java.sql.DategetDate(Object value)
Convert an Object to a Date, without an Exception
try {
    return toDate(value);
} catch (ParseException pe) {
    pe.printStackTrace();
    return null;
java.sql.DategetDate(Object value, int columnType)
get Date
if (value == null) {
    return null;
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 + ")");
DategetDate(ResultSet aResultSet, String aColumnName)
Returns the specified column of the result set as a Date.
Timestamp timestamp = aResultSet.getTimestamp(aColumnName);
return ((timestamp == null) || aResultSet.wasNull()) ? null : new Date(timestamp.getTime());
DategetDate(ResultSet res, String name)
Returns the values of the specified column as a Date.
java.sql.Date v = res.getDate(name);
return res.wasNull() ? null : new Date(v.getTime());
DategetDate(ResultSet resultSet, String columnName)
Returns a date value using a given SQL result set and column name.
Date value = null;
if (resultSet != null && columnName != null) {
    value = resultSet.getDate(columnName);
return value;
DategetDate(ResultSet rs, int colNum)
get Date
Timestamp ts = rs.getTimestamp(colNum, tzUTC); 
return ts != null ? new Date(ts.getTime()) : null;