List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:gov.nih.nci.cadsr.sentinel.tool.AlertRec.java
/** * Set the Modification date./*from w w w.java 2 s. co m*/ * * @param val_ * If null and the creation date is null, today's day and time are * used. If null and the creation date is set, the creation date is * used to set the modification date. If not null, must match the * form documented for java.sql.Timestamp.valueOf(). */ public void setMdate(String val_) { if (val_ == null) { if (_cdate == null) { Date today = new Date(); _mdate = new Timestamp(today.getTime()); } else { _mdate = _cdate; } } else { _mdate = Timestamp.valueOf(val_); } }
From source file:com.joinsystem.goku.common.utils.DateUtil.java
/** * Data??Timestamp//from w w w.ja va2 s.c o m * * @param * date * @return Timestamp */ public static Timestamp dateToTimestamp(Date date) { String temp = CHN_DATE_TIME_EXTENDED_FORMAT.format(date); return Timestamp.valueOf(temp); }
From source file:com.kylinolap.rest.service.QueryService.java
/** * @param preparedState/*from w w w .j a v a2 s.c o m*/ * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz = Object.class; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? null : Integer.valueOf(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? null : Short.valueOf(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? null : Long.valueOf(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? null : Float.valueOf(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? null : Double.valueOf(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, isNull ? null : Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? null : Byte.valueOf(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }
From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java
@Test public void getMediaThatWillBeNotVisible() throws Exception { Date today = Timestamp.valueOf("2014-03-30 11:33:45.854"); List<Media> media = MediaDAO .findByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(0).referenceDateOf(today)); assertThat(media, hasSize(0));/*from www . ja v a 2 s. c om*/ media = MediaDAO .findByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(1).referenceDateOf(today)); assertThat(media, hasSize(1)); media = MediaDAO .findByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(2).referenceDateOf(today)); assertThat(media, hasSize(0)); }
From source file:adalid.core.programmers.AbstractJavaProgrammer.java
protected String getString(Object object, Class<?> type) { if (object == null || type == null) { return null; }//from w w w . j ava 2 s . c o m String errmsg = "cannot get \"" + javaLangLess(type) + "\" from \"" + object + "\""; String string = getString(object); try { if (string == null) { return null; } else if (Boolean.class.isAssignableFrom(type)) { return "" + Boolean.valueOf(string); } else if (Character.class.isAssignableFrom(type)) { return getCharacterString(string); } else if (String.class.isAssignableFrom(type)) { return string; } else if (Byte.class.isAssignableFrom(type)) { return "" + Byte.valueOf(string); } else if (Short.class.isAssignableFrom(type)) { return "" + Short.valueOf(string); } else if (Integer.class.isAssignableFrom(type)) { return "" + Integer.valueOf(string); } else if (Long.class.isAssignableFrom(type)) { return "" + Long.valueOf(string); } else if (Float.class.isAssignableFrom(type)) { return "" + Float.valueOf(string); } else if (Double.class.isAssignableFrom(type)) { return "" + Double.valueOf(string); } else if (BigInteger.class.isAssignableFrom(type)) { return "" + new BigInteger(string); } else if (BigDecimal.class.isAssignableFrom(type)) { return "" + new BigDecimal(string); } else if (object instanceof java.util.Date && Date.class.isAssignableFrom(type)) { string = TimeUtils.jdbcDateString(object); return getString(Date.valueOf(string)); } else if (object instanceof java.util.Date && Time.class.isAssignableFrom(type)) { string = TimeUtils.jdbcTimeString(object); return getString(Time.valueOf(string)); } else if (object instanceof java.util.Date && Timestamp.class.isAssignableFrom(type)) { string = TimeUtils.jdbcTimestampString(object); return getString(Timestamp.valueOf(string)); } else { return null; } } catch (IllegalArgumentException ex) { // logger.error(errmsg, ThrowableUtils.getCause(ex)); logger.error(errmsg); return null; } }
From source file:org.jumpmind.symmetric.io.data.DbFill.java
private Timestamp randomTimestamp() { return Timestamp.valueOf(FormatUtils.TIMESTAMP_FORMATTER.format(randomDate())); }
From source file:gov.nih.nci.cadsr.sentinel.tool.AlertRec.java
/** * Set the last auto run date.//w w w . j a v a 2 s .co m * * @param val_ * If null the date is set to null. Otherwise it must match the form * documented for java.sql.Timestamp.valueOf(). */ public void setAdate(String val_) { _adate = (val_ == null) ? null : Timestamp.valueOf(val_); }
From source file:com.hp.rest.OrdersHandle.java
@POST @Path("/updateDetailInventoryManager") @Consumes(MediaType.APPLICATION_JSON)/* w w w . j a va2s. c o m*/ public Response updateDetailInventoryManager(String pInventoryManager) { SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); String time = sdf2.format(cal.getTime()); // pair to object ObjectMapper mapper = new ObjectMapper(); InventoryManagerDetail inventoryManagerDetail = new InventoryManagerDetail(); try { // File jsonFile = new File(jsonFilePath); inventoryManagerDetail = mapper.readValue(pInventoryManager, InventoryManagerDetail.class); //System.out.println(track.getmMaKhachHang()); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //Update location InventoryManagerDetailDAO inventoryManagerDetailDAO = new InventoryManagerDetailDAOImpl(); boolean st = inventoryManagerDetailDAO.update(inventoryManagerDetail); if (!st) return Response.status(200).entity(st + "").build(); //Update the order List<InventoryManagerDetail> list = new ArrayList<InventoryManagerDetail>(); list = inventoryManagerDetailDAO.getInventoryManagerDetailList(inventoryManagerDetail.getTakeOrderID()); float priceTotal = 0; for (int i = 0; i < list.size(); i++) { priceTotal += list.get(i).getPriceTotal(); } InventoryManager inventoryManager = new InventoryManager(); InventoryManagerDAO inventoryManagerDAO = new InventoryManagerDAOImpl(); inventoryManager = inventoryManagerDAO.getInventoryManager(inventoryManagerDetail.getTakeOrderID()); inventoryManager.setAfterPrivate(priceTotal - priceTotal * inventoryManager.getDiscount() / 100); inventoryManager.setOrderEditDate(Timestamp.valueOf(time)); boolean st2 = inventoryManagerDAO.update(inventoryManager); // String output = pTrack.toString(); System.out.println("____ " + pInventoryManager + "___ " + st); return Response.status(200).entity(st2 + "").build(); }
From source file:org.silverpeas.components.gallery.dao.MediaDaoIT.java
@Test public void countMediaThatWillBeNotVisible() throws Exception { Date today = Timestamp.valueOf("2014-03-30 11:33:45.854"); long nbMedia = MediaDAO .countByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(0).referenceDateOf(today)); assertThat(nbMedia, is(0L));//w w w .ja v a 2 s .c om nbMedia = MediaDAO .countByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(1).referenceDateOf(today)); assertThat(nbMedia, is(1L)); nbMedia = MediaDAO .countByCriteria(MediaCriteria.fromNbDaysBeforeThatMediaIsNotVisible(2).referenceDateOf(today)); assertThat(nbMedia, is(0L)); }
From source file:org.openmrs.module.mirebalaisreports.library.EncounterDataLibraryTest.java
@Test public void testVisitStartDatetime() throws Exception { context.setBaseEncounters(encounterIdSet); EncounterDataDefinition definition = library.getVisitStartDatetime(); EvaluatedEncounterData data = encounterDataService.evaluate(definition, context); assertThat((Timestamp) data.getData().get(e1.getId()), is(Timestamp.valueOf("2013-10-02 09:15:00"))); assertThat((Timestamp) data.getData().get(e2.getId()), is(Timestamp.valueOf("2013-10-02 09:15:00"))); assertThat((Timestamp) data.getData().get(e3.getId()), is(Timestamp.valueOf("2013-10-02 09:15:00"))); }