Example usage for java.sql Timestamp getTime

List of usage examples for java.sql Timestamp getTime

Introduction

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

Prototype

public long getTime() 

Source Link

Document

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

Usage

From source file:cn.edu.zju.acm.onlinejudge.persistence.sql.Database.java

/**
 * Gets a date value from given ResultSet.
 * /*from w  ww.  jav a2  s. c  om*/
 * @param rs
 *            the ResultSet
 * @param column
 *            the column name
 * @return a date value from given ResultSet.
 * @throws SQLException
 */
public static Date getDate(ResultSet rs, String column) throws SQLException {
    Timestamp date = rs.getTimestamp(column);
    if (date == null) {
        return null;
    }
    return new Date(date.getTime());
}

From source file:com.intbit.dao.ScheduleSocialPostDAO.java

public static JSONArray getScheduledActionsfacebook(int userid) throws SQLException {
    JSONObject json_action_facebook = new JSONObject();
    JSONArray json_array_facebook = new JSONArray();
    String query = "Select * from tbl_scheduled_entity_list" + " where entity_id=?" + " and entity_type =?"
            + " and user_id = ?";

    try (Connection conn = connectionManager.getConnection();
            PreparedStatement ps = conn.prepareStatement(query)) {
        ps.setInt(1, 0);/*from ww  w  .j  a  va 2s  .  com*/
        ps.setString(2, "facebook");
        ps.setInt(3, userid);
        try (ResultSet result_set = ps.executeQuery()) {
            while (result_set.next()) {

                JSONObject json_object = new JSONObject();
                Integer id = result_set.getInt("id");
                String schedule_title = result_set.getString("schedule_title");
                String schedule_desc = result_set.getString("schedule_desc");
                Timestamp scheduleTimestamp = result_set.getTimestamp("schedule_time");
                long scheduleTime = scheduleTimestamp.getTime();

                json_object.put("id", id);
                json_object.put("schedule_title", schedule_title);
                json_object.put("schedule_desc", schedule_desc);
                json_object.put("schedule_time", scheduleTime);
                json_array_facebook.add(json_object);
            }
        }
    }
    return json_array_facebook;
}

From source file:com.intbit.dao.ScheduleSocialPostDAO.java

public static JSONArray getScheduledActionstwitter(int userid) throws SQLException {
    JSONObject json_action_facebook = new JSONObject();
    JSONArray json_array_twitter = new JSONArray();
    String query = "Select * from tbl_scheduled_entity_list" + " where entity_id=?" + " and entity_type =?"
            + " and user_id = ?";

    try (Connection conn = connectionManager.getConnection();
            PreparedStatement ps = conn.prepareStatement(query)) {
        ps.setInt(1, 0);/*from w  ww  .j a v  a 2  s. c o m*/
        ps.setString(2, "twitter");
        ps.setInt(3, userid);

        try (ResultSet result_set = ps.executeQuery()) {
            while (result_set.next()) {

                JSONObject json_object = new JSONObject();
                Integer id = result_set.getInt("id");
                String schedule_title = result_set.getString("schedule_title");
                String schedule_desc = result_set.getString("schedule_desc");
                Timestamp scheduleTimestamp = result_set.getTimestamp("schedule_time");
                long scheduleTime = scheduleTimestamp.getTime();

                json_object.put("id", id);
                json_object.put("schedule_title", schedule_title);
                json_object.put("schedule_desc", schedule_desc);
                json_object.put("schedule_time", scheduleTime);

                json_array_twitter.add(json_object);
            }
        }
    }
    return json_array_twitter;
}

From source file:controllers.OldSensorReadingController.java

private static Long convertTimeToTimestamp(String timeString) throws ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy'T'HH:mm:ss");
    Long result = null;/*  w  w w.  ja va2  s . c  o  m*/
    Date date = dateFormat.parse(timeString);
    System.out.println(date);
    Timestamp timestamp = new Timestamp(date.getTime());
    result = timestamp.getTime();
    System.out.println(result);
    return result;
}

From source file:org.kuali.kra.proposaldevelopment.printing.xmlstream.ProposalDevelopmentXmlStream.java

public static java.util.Date toDate(java.sql.Timestamp timestamp) {
    long milliseconds = timestamp.getTime() + (timestamp.getNanos() / 1000000);
    return new java.util.Date(milliseconds);
}

From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java

public static String getDisplayValueWithDateOnly(Timestamp value) {
    return RiceConstants.getDefaultDateFormat().format(new Date(value.getTime()));
}

From source file:net.intelliant.util.UtilCommon.java

/**
 * UtilDateTime.addDaysToTimestamp(Timestamp start, Double days) type-casts input into integer resulting in loss.
 * @return a <code>Timestamp</code> value
 *///from   w  w  w .  j  a  va 2  s . com
public static Timestamp addDaysToTimestamp(Timestamp start, Double days) {
    return new Timestamp(start.getTime() + ((long) (24 * 60 * 60 * 1000 * days.longValue())));
}

From source file:com.nortal.petit.converter.util.ResultSetHelper.java

private static Long getMilliseconds(ResultSet rs, ColumnPosition column) throws SQLException {
    Timestamp timestamp = column.isNamed ? rs.getTimestamp(column.getName())
            : rs.getTimestamp(column.getIndex());
    return timestamp == null ? null : timestamp.getTime();
}

From source file:org.apache.stratos.status.monitor.internal.core.MySQLConnector.java

/**
 * Gets the service state ID from the service ID
 *
 * @param serviceID: int/*from  www.  j  a va2s. co  m*/
 * @return service state ID
 * @throws java.sql.SQLException, if the retrieval of the service state failed.
 */
public static ServiceStateInfoBean getServiceState(int serviceID) throws SQLException {
    ResultSet rs;
    Statement stmtCon = conn.createStatement();
    String sql = StatusMonitorConstants.GET_SERVICE_STATE_SQL + serviceID
            + StatusMonitorConstants.ORDER_BY_TIMESTAMP_SQL;

    stmtCon.executeQuery(sql);
    rs = stmtCon.getResultSet();
    int stateID;
    Timestamp date;
    ServiceStateInfoBean serviceStateInfoBean = new ServiceStateInfoBean();

    try {
        while (rs.next()) {
            stateID = rs.getInt(StatusMonitorConstants.STATE_ID);
            date = rs.getTimestamp(StatusMonitorConstants.TIMESTAMP);
            serviceStateInfoBean.setDate(date.getTime());
            serviceStateInfoBean.setService(serviceList.get(serviceID - 1));
            serviceStateInfoBean.setServiceID(serviceID);
            serviceStateInfoBean.setServiceState(statusList.get(stateID - 1));
        }
    } catch (SQLException e) {
        String msg = "Getting the service state failed";
        log.error(msg, e);
        throw new SQLException(msg, e);
    } finally {
        rs.close();
        stmtCon.close();
    }
    return serviceStateInfoBean;
}

From source file:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java

/**
 * Checks to see if any files in the database need to be copied to the database. A file may not
 * exist or be out of date.//from   w  w  w . jav  a2 s .c om
 */
protected static void refreshCacheFromDatabase(final String mimeType) {
    File cachePath = getCachePath();

    Hashtable<String, File> hash = new Hashtable<String, File>();
    for (File f : cachePath.listFiles()) {
        //log.info("Report Cache File["+f.getName()+"]");
        hash.put(f.getName(), f);
    }

    for (AppResourceIFace ap : AppContextMgr.getInstance().getResourceByMimeType(mimeType)) {
        // Check to see if the resource or file has changed.
        boolean updateCache = false;
        File fileFromJasperCache = hash.get(ap.getName());
        if (fileFromJasperCache == null) {
            updateCache = true;

        } else {
            Date fileDate = new Date(fileFromJasperCache.lastModified());
            Timestamp apTime = ap.getTimestampModified() == null ? ap.getTimestampCreated()
                    : ap.getTimestampModified();
            updateCache = apTime == null || fileDate.getTime() < apTime.getTime();
        }

        // If it has changed then copy the contents into the cache and delete the compiled file
        // so it forces it to be recompiled.
        if (updateCache) {
            File localFilePath = new File(cachePath.getAbsoluteFile() + File.separator + ap.getName());
            try {
                XMLHelper.setContents(localFilePath, ap.getDataAsString());

                File compiledFile = getCompiledFile(localFilePath);
                if (compiledFile.exists()) {
                    compiledFile.delete();
                }

            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JasperReportsCache.class, ex);
                throw new RuntimeException(ex);
            }
        }
    }
}