List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:com.passiveMonitorBackend.connectMonitor.model.ChangeOffSet.java
@PrePersist void createDate() { long time = new Date().getTime(); this.createDate = this.updateDate = new Timestamp(time); }
From source file:org.cloudfoundry.identity.uaa.audit.JdbcAuditServiceTests.java
@Test public void findMethodOnlyReturnsEventsWithinRequestedPeriod() { long now = System.currentTimeMillis(); auditService.log(getAuditEvent(PrincipalAuthenticationFailure, "clientA")); // Set the created column to one hour past template.update("update sec_audit set created=?", new Timestamp(now - 3600 * 1000)); auditService.log(getAuditEvent(PrincipalAuthenticationFailure, "clientA")); auditService.log(getAuditEvent(PrincipalAuthenticationFailure, "clientB")); // Find events within last 2 mins List<AuditEvent> events = auditService.find("clientA", now - 120 * 1000); assertEquals(1, events.size());/* ww w . ja v a 2 s .c o m*/ }
From source file:com.abcd.employeemaven.controller.EmployeeController.java
@RequestMapping("/saveEmployee") public ModelAndView registerUser(@ModelAttribute("employee") Employee employee, BindingResult result) throws ClassNotFoundException, SQLException { if (employee.getId() == 0) { employeeService.insert(employee); } else {/* www. j a va 2 s .c o m*/ Calendar calendar = Calendar.getInstance(); Date date = calendar.getTime(); Timestamp timestamp = new Timestamp(date.getTime()); employee.setModifiedDate(timestamp); employeeService.update(employee); } System.out.println(employee.toString()); return new ModelAndView("redirect:EmployeePage"); }
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
public static void scheduleCMAccountPing(Context context, Intent intent) { if (CMAccount.DEBUG) Log.d(TAG,/*from w ww . j a va2 s . com*/ "Scheduling CMAccount ping, starting = " + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY) + " interval (" + AlarmManager.INTERVAL_DAY + ")"); PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, reRegisterPendingIntent); }
From source file:org.kuali.mobility.push.dao.PushDeviceTupleDaoImplTest.java
@Test @DirtiesContext// w w w . j a va 2 s. co m public void testSaveTuple() { PushDeviceTuple tuple = new PushDeviceTuple(); tuple.setDeviceId(new Long(3)); tuple.setPushId(new Long(6)); Calendar cal = Calendar.getInstance(); tuple.setPostedTimestamp(new Timestamp(cal.getTimeInMillis())); tuple.setStatus(0); Long id = getDao().saveTuple(tuple); LOG.debug("========== Saved tuple with id " + id + " ========="); assertNotNull("Tuple failed to save.", id); }
From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java
@Override public int saveUser(final TUserBO user) throws SQLException { KeyHolder keyHolder = new GeneratedKeyHolder(); final String sql = "insert into T_SCS_USER(" + "ID,ACCOUNT,PWD,NAME," + "DEPT_ID,ROLE_ID,EMAIL,PHONE," + "MOBILE,FAX,POSITION,STATE," + "COMMENT,CHECK_CODE,IS_AUTO_APPROVE,CREATOR_USER_ID," + "CREATE_DT,LASTUPDATE_DT,COMP_ID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; try {//from w w w.j a v a 2 s . com this.getJdbcTemplate().update(new PreparedStatementCreator() { int i = 1; @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); ps.setInt(i++, user.getId()); ps.setString(i++, user.getAccount()); ps.setString(i++, user.getPwd()); ps.setString(i++, user.getName()); ps.setInt(i++, user.getDeptId()); ps.setInt(i++, user.getRoleId()); ps.setString(i++, user.getEmail()); ps.setString(i++, user.getPhone()); ps.setString(i++, user.getMobile()); ps.setString(i++, user.getFax()); ps.setString(i++, user.getPosition()); ps.setInt(i++, user.getState()); ps.setString(i++, user.getComment()); ps.setString(i++, user.getCheckCode()); ps.setInt(i++, user.getIsAutoApprove()); ps.setInt(i++, user.getCreatorUserId()); ps.setTimestamp(i++, new Timestamp(user.getCreateDt().getTime())); //update by CQ ps.setTimestamp(i++, new Timestamp(user.getLastupdateDt().getTime())); ps.setInt(i++, user.getCompId()); return ps; } }, keyHolder); } catch (Exception e) { throw new SQLException("??" + user.getComment() + " ID" + user.getCreatorUserId() + " " + user.getCreateDt() + " " + e.getMessage()); } return keyHolder.getKey().intValue(); }
From source file:org.pegadi.server.score.ScoreServerImpl.java
/** * Starts score recording for a new game. The <code>Score</code> object that is * returned <i>must</i> be used when calling {@link #updateScore } and * {@link #endGame }, as each score has an unique ID. * * @param domain The domain for the game. * @return A new Score object, with the score set to 0. If the domain is not known, * this method will return <code>null</code>. *///from w w w . j av a 2 s . co m public Score startGame(final Person person, String domain) { if (domain.equals("tetris")) { final String insertSql = "insert into score_tetris (userID, score, level, linecount, starttime, active) values (?, ?, ?, ?, ?, true)"; KeyHolder keyHolder = new GeneratedKeyHolder(); // The key/id of the new score is needed template.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement statement = con.prepareStatement(insertSql, new String[] { "ID" }); statement.setString(1, person.getUsername()); statement.setLong(2, 0); // score statement.setInt(3, 1); // level statement.setInt(4, 0); // lines statement.setTimestamp(5, new Timestamp((new GregorianCalendar()).getTimeInMillis())); return statement; } }, keyHolder); int scoreId = keyHolder.getKey().intValue(); return new TetrisScore(scoreId, person.getUsername(), person.getName(), 1); } else { log.error("Domain '{}' not implemented yet!", domain); return null; } }
From source file:com.redhat.rhn.manager.monitoring.ModifyFilterCommand.java
/** Set the expiration/start of the Filter to be in the * past so it will no longer be active./*from www .jav a 2s . co m*/ */ public void expireFilter() { long ctime = System.currentTimeMillis(); filter.setStartDate(new Timestamp(ctime - 1000)); filter.setExpiration(new Timestamp(ctime)); }
From source file:ke.co.tawi.babblesms.server.persistence.utils.DateResetUtil.java
/** * Reset dates for Incoming SMS./*ww w . j a v a2 s . co m*/ * * @param startDate A start date in the format yyyy-MM-dd HH:mm:ss * @param endDate An end date in the format yyyy-MM-dd HH:mm:ss */ public void resetIncomingDates(String startDate, String endDate) { SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Example 2011-06-01 00:16:45" List<String> uuids = new ArrayList<>(); RandomDataGenerator generator = new RandomDataGenerator(); // Get UUIDs of Incoming SMS are in the database try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement("SELECT uuid FROM incominglog;");) { ResultSet rset = pstmt.executeQuery(); while (rset.next()) { uuids.add(rset.getString("uuid")); } } catch (SQLException e) { logger.error("SQLException when getting uuids of incominglog."); logger.error(ExceptionUtils.getStackTrace(e)); } try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn .prepareStatement("UPDATE incominglog SET logTime=? " + "WHERE Uuid=?;");) { long start = dateFormatter.parse(startDate).getTime(); long end = dateFormatter.parse(endDate).getTime(); for (String uuid : uuids) { pstmt.setTimestamp(1, new Timestamp(generator.nextLong(start, end))); pstmt.setString(2, uuid); pstmt.executeUpdate(); } } catch (SQLException e) { logger.error("SQLException when trying to reset dates of incomingLog."); logger.error(ExceptionUtils.getStackTrace(e)); } catch (ParseException e) { logger.error("ParseException when trying to reset dates of incomingLog."); logger.error(ExceptionUtils.getStackTrace(e)); } }
From source file:com.phonemetra.account.util.AccountUtils.java
public static void scheduleAccountPing(Context context, Intent intent) { if (Account.DEBUG) Log.d(TAG,/*w w w .j av a 2s. c o m*/ "Scheduling Account ping, starting = " + new Timestamp(SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY) + " interval (" + AlarmManager.INTERVAL_DAY + ")"); PendingIntent reRegisterPendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, AlarmManager.INTERVAL_DAY, reRegisterPendingIntent); }