Java Utililty Methods SQL Time

List of utility methods to do SQL Time

Description

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

Method

DateextractTime(Date date)
Returns a date with "zero" date.
return extractTime(date, getDefaultTimeZone());
voidgetCalTime(Time startTime, Calendar cal)
get Cal Time
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(startTime);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
cal.set(year, month, day, hour, min, sec);
...
ClassgetClassForSqlType(String sqlType, Class dateTimeClass)
Returns the Java class for a given SQL type.
sqlType = sqlType.toUpperCase();
sqlType = sqlType.split(" ")[0].trim();
if (SQL_TYPES.containsKey(sqlType)) {
    sqlType = SQL_TYPES.get(sqlType);
Class<?> mappedClass = null;
for (Class<?> clazz : SUPPORTED_TYPES.keySet()) {
    if (SUPPORTED_TYPES.get(clazz).equalsIgnoreCase(sqlType)) {
...
longgetClosestIDByTime(Connection con, String table, long time)
get Closest ID By Time
String sql = "SELECT `id` FROM `" + table + "` WHERE `created_1` < " + time
        + " ORDER BY `id` DESC LIMIT 1;";
CallableStatement stmt = con.prepareCall(sql);
ResultSet rs = stmt.executeQuery();
rs.next();
long closestId = rs.getLong(1);
rs.close();
return closestId;
...
StringgetDateTimeValue(ResultSet result, String strField, String strDateFormat)
get Date Time Value
String strValueReturn;
Timestamp timestamp = result.getTimestamp(strField);
if (result.wasNull()) {
    strValueReturn = "";
} else {
    SimpleDateFormat formatter = new SimpleDateFormat(strDateFormat);
    strValueReturn = formatter.format(timestamp);
return strValueReturn;
StringgetDBTime(String yyyyMMddHHmmss)
get DB Time
String d = "";
try {
    SimpleDateFormat temp = new SimpleDateFormat("yyyyMMddHHmmss");
    d = new java.sql.Timestamp(temp.parse(yyyyMMddHHmmss).getTime()).toString();
} catch (Exception ex) {
    ex.printStackTrace();
return d;
...
StringgetFormatDateTimeDesc(long longDate)
get Format Date Time Desc
return new Timestamp(longDate).toString().substring(0, 19);
java.util.DategetFullDateTime(ResultSet rs, String column)
Returns the value of a DATETIME column in the current row of an SQL result set, formatted as a date.
return convertDateTimeString(rs.getString(column));
TimestampgetFutureTime(int month)
get Future Time
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, month);
return new Timestamp(c.getTimeInMillis());
TimestampgetGrandfatheredTime()
get Grandfathered Time
Timestamp grandfatheredTime = Timestamp.valueOf("2000-01-01 00:00:00.0");
return grandfatheredTime;