List of usage examples for java.sql Timestamp valueOf
@SuppressWarnings("deprecation") public static Timestamp valueOf(LocalDateTime dateTime)
From source file:com.hp.rest.OrdersHandle.java
@POST @Path("/putInventoryManager") @Consumes(MediaType.APPLICATION_JSON)//from w w w . j av a 2 s .c o m public Response putInventoryManager(String pInventoryManager) { // pair to object ObjectMapper mapper = new ObjectMapper(); InventoryManager inventoryManager = new InventoryManager(); try { // File jsonFile = new File(jsonFilePath); inventoryManager = mapper.readValue(pInventoryManager, InventoryManager.class); //System.out.println(track.getmMaKhachHang()); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date today = new Date(); if (inventoryManager != null) { inventoryManager.setTakeOrderDate(Timestamp.valueOf(df.format(today))); inventoryManager.setDeliveryDate(Timestamp.valueOf(df.format(today))); } //Update location InventoryManagerDAO inventoryManagerDAO = new InventoryManagerDAOImpl(); boolean st = inventoryManagerDAO.saveOrUpdate(inventoryManager); // String output = pTrack.toString(); System.out.println("pTakeOrder: " + st + "____ " + pInventoryManager); return Response.status(200).entity(st + "").build(); }
From source file:fr.juanwolf.mysqlbinlogreplicator.component.DomainClassAnalyzerTest.java
@Test public void instantiateField_should_set_the_timestamp_with_the_specific_timestamp() throws ReflectiveOperationException, ParseException { // Given// ww w . j a v a2 s . c o m String timestampString = "2015-09-26 12:30:15"; Timestamp timestamp = Timestamp.valueOf(timestampString); domainClassAnalyzer.postConstruct(); User user = (User) domainClassAnalyzer.generateInstanceFromName("user"); // When domainClassAnalyzer.instantiateField(user, user.getClass().getDeclaredField("creationTimestamp"), timestampString, ColumnType.TIMESTAMP.getCode(), "user"); // Then assertThat(user.getCreationTimestamp()).isEqualTo(timestamp); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastCartridgeStatsMonthlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {//from www. ja va 2s . c om connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM CARTRIDGE_STATS_LAST_MONTHLY_TS WHERE ID='LatestTS'"; PreparedStatement ps = connection.prepareStatement(sql); ResultSet resultSet = ps.executeQuery(); if (resultSet.next()) { lastSummaryTs = resultSet.getTimestamp("TIMESTMP"); } else { lastSummaryTs = new Timestamp(0); } DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO CARTRIDGE_STATS_LAST_MONTHLY_TS (ID, TIMESTMP) VALUES('LatestTS',?) ON DUPLICATE KEY UPDATE TIMESTMP=?"; PreparedStatement ps1 = connection.prepareStatement(currentSql); ps1.setTimestamp(1, currentTs); ps1.setTimestamp(2, currentTs); ps1.execute(); } catch (SQLException e) { log.error( "Error occurred while trying to get and update the last monthly timestamp for cartridge stats. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:com.hp.rest.UtilitiesHandle.java
@POST @Path("/putForLeave") @Consumes(MediaType.APPLICATION_JSON)/*from w w w .ja v a 2 s . c o m*/ public Response putForLeave(String pData) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ForLeaveDAO forLeaveDAO = new ForLeaveDAOImpl(); ObjectMapper mapper = new ObjectMapper(); ForLeave forLeave = new ForLeave(); try { forLeave = mapper.readValue(pData, ForLeave.class); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (forLeave == null) return Response.status(200).entity("false").build(); Date today = new Date(); forLeave.setTimeAt(Timestamp.valueOf(dateFormat.format(today))); List<ForLeave> forLeaveList = forLeaveDAO.getForLeaveList(forLeave.getStaff(), forLeave.getTimeAt()); if (forLeaveList != null && forLeaveList.size() > 0) { return Response.status(200).entity("existforleave").build(); } forLeave.setCreatedTime(Timestamp.valueOf(dateFormat.format(today))); return Response.status(200).entity(forLeaveDAO.saveOrUpdate(forLeave) + "").build(); }
From source file:mondrian.spi.impl.JdbcDialectImpl.java
public void quoteTimestampLiteral(StringBuilder buf, String value) { // NOTE jvs 1-Jan-2007: See quoteTimestampLiteral for explanation. try {// w w w . java2 s .c o m Timestamp.valueOf(value); } catch (IllegalArgumentException ex) { throw new NumberFormatException("Illegal TIMESTAMP literal: " + value); } buf.append("TIMESTAMP "); Util.singleQuoteString(value, buf); }
From source file:org.elasticsearch.querydoge.QueryDogeTest.java
/** * @return/*from w w w .ja va 2 s . c o m*/ */ private long generateRandomTimeStamp() { long offset = Timestamp.valueOf("2013-01-01 00:00:00").getTime(); long end = Timestamp.valueOf("2014-01-01 00:00:00").getTime(); long diff = end - offset + 1; Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff)); return rand.getTime(); }
From source file:org.ofbiz.core.entity.GenericEntity.java
/** * Sets the named field to the passed value, converting the value from a String to the correct type using * {@code Type.valueOf()} or similar.//from w ww . j a v a 2s .com * <p> * <strong>WARNING</strong>: calling this for an {@link FieldType#OBJECT OBJECT} field is ambiguous, because * you could mean either that the {@code String} is the Base64-encoded representation of the object and * should be be deserialized or that the {@code String} is the actual object to be stored. Since this * method is intended for use in restoring the entity from an XML export, it assumes that the value is * the Base64-encoding of an arbitrary object and attempts to deserialize it. If this is not what is * intended, then it is up to the caller to use {@link #set(String, Object)} for those fields, instead. * </p> * * @param name The field name to set * @param value The String value to convert and set */ public void setString(String name, String value) { ModelField field = getModelEntity().getField(name); if (field == null) { throw new IllegalArgumentException( "[GenericEntity.setString] \"" + name + "\" is not a field of " + entityName); } final ModelFieldType type = getModelFieldType(field.getType()); final FieldType fieldType = SqlJdbcUtil.getFieldType(type.getJavaType()); switch (fieldType) { case STRING: set(name, value); break; case TIMESTAMP: set(name, Timestamp.valueOf(value)); break; case TIME: set(name, Time.valueOf(value)); break; case DATE: set(name, Date.valueOf(value)); break; case INTEGER: set(name, Integer.valueOf(value)); break; case LONG: set(name, Long.valueOf(value)); break; case FLOAT: set(name, Float.valueOf(value)); break; case DOUBLE: set(name, Double.valueOf(value)); break; case BOOLEAN: set(name, Boolean.valueOf(value)); break; case OBJECT: set(name, deserialize(decodeBase64(value))); break; case CLOB: set(name, value); break; case BLOB: set(name, decodeBase64(value)); break; case BYTE_ARRAY: set(name, decodeBase64(value)); break; default: throw new UnsupportedOperationException("Unsupported type: " + fieldType); } }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for converting format dd-MM-yyyy to date * //from w w w .j av a 2 s.co m * @param strDate * @return * @throws ParseException */ public static Timestamp convertStringToTimestamp(String strDate) throws ParseException { Calendar c = GregorianCalendar.getInstance(); c.setTimeInMillis(Long.valueOf(strDate)); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.applyPattern(DateTimeConstants.TIMESTAMP_FORMAT); String ts = sdf.format(c.getTime()); return Timestamp.valueOf(ts); }
From source file:data_gen.Data_gen.java
private static void generate_date(HashMap<String, Object> fields, String key, String value) { try {//from w ww. ja v a 2s. co m String[] values = value.split(":"); String trim_val = values[1].substring(1, values[1].length() - 1); String range[] = trim_val.split(","); for (int i = 0; i < 2; i++) { String[] tokens = range[i].split("-"); if (tokens.length == 1) { Random rand = new Random(); String month = String.valueOf(rand.nextInt(11) + 1); String day = String.valueOf(rand.nextInt(27) + 1); if (month.length() == 1) { month = "0" + month; } if (day.length() == 1) { day = "0" + day; } range[i] += "-" + month + "-" + day; } if (tokens.length == 2) { Random rand = new Random(); String day = String.valueOf(rand.nextInt(27) + 1); if (day.length() == 1) { day = "0" + day; } range[i] += "-" + day; } } //////////////////////////////////////////// range[0] += " 00:00:00"; range[1] += " 23:59:59"; long begin = Timestamp.valueOf(range[0]).getTime(); long end = Timestamp.valueOf(range[1]).getTime(); long diff = end - begin + 1; Timestamp rand = new Timestamp(begin + (long) (Math.random() * diff)); SimpleDateFormat date = new SimpleDateFormat("yyyy-M-d HH:mm:ss"); String time = date.format(rand); fields.put(key, time); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Make sure you have the right date range format in configration file"); System.out.println("example: date:[2013-04-07,2014-09]" + "\n"); System.exit(0); } }
From source file:org.apache.jmeter.protocol.jdbc.AbstractJDBCTestElement.java
private void setArgument(PreparedStatement pstmt, String argument, int targetSqlType, int index) throws SQLException { switch (targetSqlType) { case Types.INTEGER: pstmt.setInt(index, Integer.parseInt(argument)); break;/* w ww .java 2 s .c o m*/ case Types.DECIMAL: case Types.NUMERIC: pstmt.setBigDecimal(index, new BigDecimal(argument)); break; case Types.DOUBLE: case Types.FLOAT: pstmt.setDouble(index, Double.parseDouble(argument)); break; case Types.CHAR: case Types.LONGVARCHAR: case Types.VARCHAR: pstmt.setString(index, argument); break; case Types.BIT: case Types.BOOLEAN: pstmt.setBoolean(index, Boolean.parseBoolean(argument)); break; case Types.BIGINT: pstmt.setLong(index, Long.parseLong(argument)); break; case Types.DATE: pstmt.setDate(index, Date.valueOf(argument)); break; case Types.REAL: pstmt.setFloat(index, Float.parseFloat(argument)); break; case Types.TINYINT: pstmt.setByte(index, Byte.parseByte(argument)); break; case Types.SMALLINT: pstmt.setShort(index, Short.parseShort(argument)); break; case Types.TIMESTAMP: pstmt.setTimestamp(index, Timestamp.valueOf(argument)); break; case Types.TIME: pstmt.setTime(index, Time.valueOf(argument)); break; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: pstmt.setBytes(index, argument.getBytes()); break; case Types.NULL: pstmt.setNull(index, targetSqlType); break; default: pstmt.setObject(index, argument, targetSqlType); } }