Example usage for java.sql Time getTime

List of usage examples for java.sql Time getTime

Introduction

In this page you can find the example usage for java.sql Time getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:GetDateFromMySql.java

public static void main(String args[]) {
    ResultSet rs = null;//  w w w.j  av a  2  s . co m
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = getMySQLConnection();
        stmt = conn.createStatement();
        rs = stmt.executeQuery("select timeCol, dateCol, dateTimeCol from dateTimeTable");
        while (rs.next()) {
            java.sql.Time dbSqlTime = rs.getTime(1);
            java.sql.Date dbSqlDate = rs.getDate(2);
            java.sql.Timestamp dbSqlTimestamp = rs.getTimestamp(3);
            System.out.println("dbSqlTime=" + dbSqlTime);
            System.out.println("dbSqlDate=" + dbSqlDate);
            System.out.println("dbSqlTimestamp=" + dbSqlTimestamp);

            java.util.Date dbSqlTimeConverted = new java.util.Date(dbSqlTime.getTime());
            java.util.Date dbSqlDateConverted = new java.util.Date(dbSqlDate.getTime());
            System.out.println("in standard date");
            System.out.println(dbSqlTimeConverted);
            System.out.println(dbSqlDateConverted);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:adalid.commons.util.TimeUtils.java

public static java.util.Date getSqlExtension(java.util.Date util) {
    if (util == null) {
        return null;
    } else if (util instanceof Date || util instanceof Time || util instanceof Timestamp) {
        return util;
    } else {/*from w w w .  ja v  a 2 s  .c om*/
        long milliseconds = util.getTime();
        Date date = newDate(util);
        if (date.getTime() == milliseconds) {
            return date;
        }
        Time time = newTime(util);
        if (time.getTime() == milliseconds) {
            return time;
        }
        return new Timestamp(milliseconds);
    }
}

From source file:de.interseroh.report.formatters.TimeFormatter.java

@Override
public String print(Time date, Locale locale) {
    return getDateFormat(locale).format(new java.util.Date(date.getTime()));
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

@Override
public Time getCopy(Object object) {
    Time t = (Time) object;
    return t != null ? new Time(t.getTime()) : null;
}

From source file:com.wabacus.system.datatype.TimeType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time tt = rs.getTime(column);
    if (tt == null)
        return null;
    return new Date(tt.getTime());
}

From source file:com.wabacus.system.datatype.TimeType.java

public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time tt = rs.getTime(iindex);
    if (tt == null)
        return null;
    return new Date(tt.getTime());
}

From source file:org.apache.ddlutils.platform.DefaultValueHelper.java

/**
 * Converts the given default value from the specified original to the target
 * jdbc type.//from   w w w.jav  a 2 s.  c  om
 * 
 * @param defaultValue     The default value
 * @param originalTypeCode The original type code
 * @param targetTypeCode   The target type code
 * @return The converted default value 
 */
public String convert(String defaultValue, int originalTypeCode, int targetTypeCode) {
    String result = defaultValue;

    if (defaultValue != null) {
        switch (originalTypeCode) {
        case Types.BIT:
        case Types.BOOLEAN:
            result = convertBoolean(defaultValue, targetTypeCode).toString();
            break;
        case Types.DATE:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Date date = Date.valueOf(result);

                    return new Timestamp(date.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        case Types.TIME:
            if (targetTypeCode == Types.TIMESTAMP) {
                try {
                    Time time = Time.valueOf(result);

                    return new Timestamp(time.getTime()).toString();
                } catch (IllegalArgumentException ex) {
                }
            }
            break;
        }
    }
    return result;
}

From source file:com.wabacus.system.datatype.CTimeType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time ctt = rs.getTime(column);
    if (ctt == null)
        return null;
    Calendar cd = Calendar.getInstance();
    cd.setTimeInMillis(ctt.getTime());
    return cd;//w  ww .j  ava  2s. com
}

From source file:com.wabacus.system.datatype.CTimeType.java

public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException {
    java.sql.Time ctt = rs.getTime(iindex);
    if (ctt == null)
        return null;
    Calendar cd = Calendar.getInstance();
    cd.setTimeInMillis(ctt.getTime());
    return cd;// w ww.  j a v a 2s.  c  om
}

From source file:com.impetus.kundera.property.accessor.SQLTimeAccessor.java

@Override
public String toString(Object object) {
    Time time = (Time) object;

    if (time == null) {
        return null;
    }/*from   w w w  .  j  a v  a 2s  .  c  o m*/

    return String.valueOf(time.getTime());
}