List of usage examples for java.sql Timestamp Timestamp
public Timestamp(long time)
From source file:it.av.eatt.ocm.util.DateUtil.java
/** * Return the actual time /*from ww w. j a v a 2 s. c o m*/ * * @return Timestamp */ public static Timestamp getTimestamp() { return new Timestamp(Calendar.getInstance().getTimeInMillis()); }
From source file:net.duckling.ddl.util.Utility.java
public static Timestamp date2Timestamp(Date date) { if (date == null) { return null; } else {//from w ww .j av a 2 s. c o m return new Timestamp(date.getTime()); } }
From source file:Main.java
public static PreparedStatement createFieldsInsert(Connection conn, int layerId, String name, String description, String fieldId, String fieldType, String sid, String sname, String sdesc, boolean indb, boolean enabled, boolean namesearch, boolean defaultlayer, boolean intersect, boolean layerbranch, boolean analysis, boolean addToMap) throws SQLException { // TOOD slightly different statement if sdesc is null... PreparedStatement stFieldsInsert = conn.prepareStatement( "INSERT INTO fields (name, id, \"desc\", type, spid, sid, sname, sdesc, indb, enabled, last_update, namesearch, defaultlayer, \"intersect\", layerbranch, analysis, addtomap)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); stFieldsInsert.setString(1, name);/*from w ww . j a v a2s . c om*/ stFieldsInsert.setString(2, fieldId); stFieldsInsert.setString(3, description); stFieldsInsert.setString(4, fieldType); stFieldsInsert.setString(5, Integer.toString(layerId)); stFieldsInsert.setString(6, sid); stFieldsInsert.setString(7, sname); if (sdesc == null || sdesc.isEmpty()) { stFieldsInsert.setNull(8, Types.VARCHAR); } else { stFieldsInsert.setString(8, sdesc); } stFieldsInsert.setBoolean(9, indb); stFieldsInsert.setBoolean(10, enabled); stFieldsInsert.setTimestamp(11, new Timestamp(System.currentTimeMillis())); stFieldsInsert.setBoolean(12, namesearch); stFieldsInsert.setBoolean(13, defaultlayer); stFieldsInsert.setBoolean(14, intersect); stFieldsInsert.setBoolean(15, layerbranch); stFieldsInsert.setBoolean(16, analysis); stFieldsInsert.setBoolean(17, addToMap); return stFieldsInsert; }
From source file:com.yahoo.elide.utils.coerce.converters.EpochToDateConverter.java
private static <T> T longToDate(Class<T> cls, Long epoch) throws ReflectiveOperationException { if (ClassUtils.isAssignable(cls, java.sql.Date.class)) { return (T) new java.sql.Date(epoch); } else if (ClassUtils.isAssignable(cls, Timestamp.class)) { return (T) new Timestamp(epoch); } else if (ClassUtils.isAssignable(cls, Time.class)) { return (T) new Time(epoch); } else if (ClassUtils.isAssignable(cls, Date.class)) { return (T) new Date(epoch); } else {/*from w w w.j av a 2s . co m*/ throw new UnsupportedOperationException("Cannot convert to " + cls.getSimpleName()); } }
From source file:com.sql.Audit.java
/** * Adds an entry to the audit table/*from ww w .j av a 2 s.co m*/ * @param action performed action to be stored */ public static void addAuditEntry(String action) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO Audit VALUES" + "(?,?,?)"; ps = conn.prepareStatement(sql); ps.setTimestamp(1, new Timestamp(System.currentTimeMillis())); ps.setInt(2, 0); ps.setString(3, action == null ? "MISSING ACTION" : StringUtils.left(action, 255)); ps.executeUpdate(); } catch (SQLException ex) { if (ex.getCause() instanceof SQLServerException) { addAuditEntry(action); } } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); } }
From source file:com.fluke.util.Util.java
public static Timestamp getTimeStamp(String date) { try {/* www . j a v a 2s .co m*/ return new Timestamp(getDate(date).getTime()); } catch (ParseException ex) { throw new RuntimeException(ex); } }
From source file:com.dc.gameserver.extComponents.Kit.DateUtil.java
/** * /* w w w . jav a 2s . c o m*/ * 5 * @param lastTime * @param nowTime * @return */ @SuppressWarnings("deprecation") public static int getDay(Timestamp lastTime, Timestamp nowTime) { if (nowTime == null) nowTime = new Timestamp(System.currentTimeMillis()); if (lastTime == null) return 1; if (lastTime.getHours() < 5) { // 1-3 if (nowTime.getHours() < 5) { return getDiffDay(nowTime, lastTime); // 1-4 } else { return getDiffDay(nowTime, lastTime) + 1; } } else { //2-3 if (nowTime.getHours() < 5) { return getDiffDay(nowTime, lastTime) - 1; //2-4 } else { return getDiffDay(nowTime, lastTime); } } }
From source file:com.daphne.es.common.test.BaseUserIT.java
public User createUser() { User user = new User(); user.setUsername("zhangkaitao$$$" + System.nanoTime() + RandomStringUtils.random(10)); user.setPassword("123456"); user.setRegisterDate(new Date()); BaseInfo baseInfo = new BaseInfo(); baseInfo.setRealname("zhangkaitao"); baseInfo.setSex(Sex.male);//w ww .j a v a 2 s . c o m baseInfo.setBirthday(new Timestamp(System.currentTimeMillis())); baseInfo.setAge(15); user.setBaseInfo(baseInfo); SchoolInfo primary = new SchoolInfo(); primary.setName("abc"); primary.setType(SchoolType.primary_school); user.addSchoolInfo(primary); SchoolInfo secondary = new SchoolInfo(); secondary.setName("bcd"); secondary.setType(SchoolType.secondary_school); user.addSchoolInfo(secondary); SchoolInfo high = new SchoolInfo(); high.setName("cde"); high.setType(SchoolType.high_school); user.addSchoolInfo(high); SchoolInfo university = new SchoolInfo(); university.setName("def"); university.setType(SchoolType.university); user.addSchoolInfo(university); return user; }
From source file:com.fluke.data.intraday.Series.java
/** * * @return The Timestamp */ public Timestamp getTimestamp() { return new Timestamp(Timestamp * 1000); }
From source file:edu.depaul.armada.util.TestUtil.java
public static Container newContainer() { Container container = new Container(); container.setCAdvisorURL("http://localhost:8080/cAdvisor"); container.setContainerUniqueId(UUID.randomUUID().toString()); container.setName("test-name"); container.setTimestamp(new Timestamp(System.currentTimeMillis())); return container; }