Example usage for java.sql Timestamp Timestamp

List of usage examples for java.sql Timestamp Timestamp

Introduction

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

Prototype

public Timestamp(long time) 

Source Link

Document

Constructs a Timestamp object using a milliseconds time value.

Usage

From source file:ca.qc.adinfo.rouge.mail.db.MailDb.java

public static boolean sendMail(DBManager dbManager, long fromId, long toId, RougeObject content) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;//from w  w  w. j  ava 2s  .c  om
    String sql = null;

    sql = "INSERT INTO rouge_mail (`from`, `to`, `content`, `status`, `time_sent`) " + "VALUES (?, ?, ?, ?, ?)";

    try {
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);

        stmt.setLong(1, fromId);
        stmt.setLong(2, toId);
        stmt.setString(3, content.toJSON().toString());
        stmt.setString(4, "unr");
        stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis()));

        int ret = stmt.executeUpdate();

        return (ret > 0);

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return false;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:edu.depaul.armada.util.TestUtil.java

public static ContainerLog newContainerLog() {
    ContainerLog log = new ContainerLog();
    log.setTimestamp(new Timestamp(0));
    log.setCpuUsed(RandomUtils.nextLong(0, 100));
    log.setCpuTotal(100);/*from   w  ww.j  av a2 s  .c  om*/
    log.setMemUsed(RandomUtils.nextLong(0, 100));
    log.setMemTotal(100);
    log.setDiskUsed(RandomUtils.nextLong(0, 100));
    log.setDiskTotal(100);
    return log;
}

From source file:com.springmvc.dao.TimeLogDAO.java

public void updateLogin(TimeLog timeLog, User user) {
    TimeLog timeLogToUpdate = getTimeLog(timeLog.getId());

    Date date = new Date();
    Timestamp time = new Timestamp(date.getTime());
    timeLogToUpdate.setLogin(time);/*from   w  ww . j  a  v  a2  s  .c  o  m*/
    timeLogToUpdate.setUser(user);

    getCurrentSession().update(timeLogToUpdate);
}

From source file:net.granoeste.commons.util.DateUtils.java

/**
 * get the Timestamp now.//  www.j av  a 2  s  .co m
 *
 * @return Timestamp
 */
public static Timestamp getNowTimestamp() {
    final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    return timestamp;
}

From source file:com.microsoft.sqlserver.testframework.sqlType.SqlDateTime2.java

public SqlDateTime2() {
    super("datetime2", JDBCType.TIMESTAMP, null, null);
    try {/*from  w w  w .  j av a2s. c  o  m*/
        minvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME2.minValue).getTime());
        maxvalue = new Timestamp(dateFormat.parse((String) SqlTypeValue.DATETIME2.maxValue).getTime());
    } catch (ParseException ex) {
        fail(ex.getMessage());
    }
    this.precision = 7;
    this.variableLengthType = VariableLengthType.Precision;
    generatePrecision();
    formatter = new DateTimeFormatterBuilder().appendPattern(basePattern)
            .appendFraction(ChronoField.NANO_OF_SECOND, 0, this.precision, true).toFormatter();

}

From source file:com.anthony.forumspring.dao.CommentaireDao.java

@Override
public void InsertNewCommentaire(Commentaire commentaire) {
    Calendar calendar = Calendar.getInstance();
    Timestamp date_commentaire = new Timestamp(calendar.getTime().getTime());

    String sql = "INSERT INTO COMMENTAIRES(CAT_ID, TOPIC_ID, USERNAME, COMMENT_NUMBER,COMMENT_DATE_DETAILS, COMMENT_TEXT,VALIDATION,MEDIA) values (?,?,?,?,?,?,?,?)";
    jdbcTemplate.update(sql,//from  w ww .ja va 2s  .  c o m
            new Object[] { commentaire.getCat_id(), commentaire.getTopic_id(), commentaire.getUsername(), 0,
                    date_commentaire, commentaire.getComment_text(), 0, commentaire.getMedia() });

}

From source file:ltistarter.model.BaseEntity.java

@PrePersist
void preCreate() {
    this.createdAt = this.updatedAt = new Timestamp(System.currentTimeMillis());
}

From source file:Transaction.java

public void doWork() {
    try {//  w w w . j av a  2  s.c  om
        java.util.Date now = new java.util.Date();
        connection.setAutoCommit(false);
        Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        ResultSet rs = statement.executeQuery("SELECT * FROM acc_add WHERE acc_id = 1034055 and ts = 0");

        // set old row ts = current time
        rs.next();
        rs.updateTimestamp("ts", new Timestamp(now.getTime()));
        rs.updateRow();

        rs.moveToInsertRow();
        rs.updateInt("add_id", rs.getInt("add_id"));
        rs.updateInt("acc_id", rs.getInt("acc_id"));
        rs.updateString("name", rs.getString("name"));
        rs.updateString("address1", "555 East South Street");
        rs.updateString("address2", "");
        rs.updateString("address3", "");
        rs.updateString("city", rs.getString("city"));
        rs.updateString("state", rs.getString("state"));
        rs.updateString("zip", rs.getString("zip"));
        rs.updateTimestamp("ts", new Timestamp(0));
        rs.updateTimestamp("act_ts", new Timestamp(now.getTime()));
        rs.insertRow();
        connection.commit();

        rs.close();
        statement.close();
        connection.close();

    } catch (Exception e) {
        try {
            connection.rollback();
        } catch (SQLException error) {
        }
        e.printStackTrace();
    }
}

From source file:ltistarter.model.BaseEntity.java

@PreUpdate
void preUpdate() {
    this.updatedAt = new Timestamp(System.currentTimeMillis());
}

From source file:com.ibm.mil.readyapps.telco.analytics.OperationalAnalyticsReporter.java

/**
 * pageTransition() sends an Operational Analytics log anytime a user changes from one screen
 * to another./*from  w ww  .j  av a 2 s .c o m*/
 *
 * @param src The source page that the user is navigating from.
 * @param dst The destination page that the user navigates to, it refers to there current
 *            screen.
 * @param dwellTime The dwellTime in milliseconds that the user spent on the source page
 *                  before transitioning to the destination page.
 */
public static void pageTransition(@AnalyticsCnsts.Page String src, @AnalyticsCnsts.Page String dst,
        long dwellTime) {
    Date date = new Date();
    Timestamp curTime = new Timestamp(date.getTime());

    String json = gson.toJson(new AnalyticsPageTransition(src, dst, curTime), AnalyticsPageTransition.class);
    JSONObject jsonObject = null;
    try {
        jsonObject = new JSONObject(json);
        jsonObject.put("_activity", "pageTransition");
        String dwellField = src + "_dwellTime";
        double dwellTimeSeconds = (double) dwellTime / 1000;
        jsonObject.put(dwellField, dwellTimeSeconds);

        Log.i("TEST", "PAGE_TRANSITION : " + jsonObject.toString());

        WLAnalytics.log("Page transition recorded.", jsonObject);

        WLAnalytics.send();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}