List of usage examples for java.sql Timestamp toString
@SuppressWarnings("deprecation") public String toString()
From source file:pt.fct.di.benchmarks.TPCW_Riak.database.TPCW_Riak_Executor.java
public void shoppingCartInteraction(int item, boolean create, String cart_id) throws Exception { ShoppingCart shop_c;/*from www. j a v a2s .com*/ IRiakObject shop_cObj; if (create) { Timestamp stamp = new Timestamp(System.currentTimeMillis()); shop_c = new ShoppingCart(cart_id); shop_c.setCartInfo("SC_DATE", stamp.toString()); shop_cObj = RiakObjectBuilder.newBuilder("shopping_cart", cart_id).build(); } else { Bucket bucket = getBucket("shopping_cart"); shop_cObj = bucket.fetch(cart_id).execute(); shop_c = (ShoppingCart) GSON.fromJson(shop_cObj.getValueAsString(), ShoppingCart.class); } Bucket bucket = getBucket("item"); Item itemObj = (Item) GSON.fromJson(bucket.fetch(item + "").execute().getValueAsString(), Item.class); SCLine sc_line = shop_c.getSCLine(item); if (sc_line != null) { sc_line.setSCL_QTY(sc_line.getSCL_QTY() + 1); } else { sc_line = new SCLine(item); sc_line.setSCL_COST(itemObj.getI_COST()); sc_line.setSCL_SRP(itemObj.getI_SRP()); sc_line.setSCL_TITLE(itemObj.getI_TITLE()); sc_line.setSCL_BACKING(itemObj.getI_BACKING()); sc_line.setSCL_QTY(1); sc_line.setI_ID(itemObj.getI_id()); shop_c.addSCLine(sc_line); // getBucket("sc_lines").store(cart_id + "_" + item, // GSON.toJson(sc_line)).execute(); } shop_cObj.setValue(GSON.toJson(shop_c)); getBucket("shopping_Cart").store(cart_id + "", GSON.toJson(shop_c).toString()).execute(); }
From source file:com.splicemachine.derby.impl.load.HdfsImportIT.java
@Test public void testImportISODateFormat() throws Exception { PreparedStatement ps = methodWatcher.prepareStatement(format("call SYSCS_UTIL.IMPORT_DATA(" + "'%s'," + // schema name "'%s'," + // table name "null," + // insert column list "'%s'," + // file path "','," + // column delimiter "'%s'," + // character delimiter "'yyyy-MM-dd''T''HH:mm:ss.SSS''Z'''," + // timestamp format "null," + // date format "null," + // time format "%d," + // max bad records "'%s'," + // bad record dir "null," + // has one line records "null)", // char set spliceSchemaWatcher.schemaName, TABLE_9, getResourceDirectory() + "iso_order_date.csv", "\"", 0, BADDIR.getCanonicalPath())); ps.execute();//from w w w . j a va2 s .c o m ResultSet rs = methodWatcher .executeQuery(format("select * from %s.%s", spliceSchemaWatcher.schemaName, TABLE_9)); List<String> results = Lists.newArrayList(); while (rs.next()) { Timestamp order_date = rs.getTimestamp(1); assertNotNull("order_date incorrect", order_date); Assert.assertEquals(order_date.toString(), "2013-06-06 15:02:48.0"); results.add(String.format("order_date:%s", order_date)); } Assert.assertTrue("import failed!", results.size() == 1); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastUsageDailyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {//from w w w .j a v a 2 s . c o m connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM USAGE_LAST_DAILY_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 HH:00:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO USAGE_LAST_DAILY_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 daily timestamp. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastUsageHourlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {/* www. j a v a2 s . c o m*/ connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM USAGE_LAST_HOURLY_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 HH:mm:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO USAGE_LAST_HOURLY_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 hourly timestamp. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastUsageMonthlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {//from w w w . j a va2 s . c om connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM USAGE_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 USAGE_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. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:com.splicemachine.derby.impl.load.HdfsImportIT.java
@Test public void testImportCustomTimeFormatMicro() throws Exception { methodWatcher.executeUpdate("delete from " + spliceTableWatcher9); PreparedStatement ps = methodWatcher.prepareStatement(format("call SYSCS_UTIL.IMPORT_DATA(" + "'%s'," + // schema name "'%s'," + // table name "null," + // insert column list "'%s'," + // file path "null," + // column delimiter "'%s'," + // character delimiter "'yyyy-MM-dd HH:mm:ss.SSSSSS'," + // timestamp format "null," + // date format "null," + // time format "%d," + // max bad records "'%s'," + // bad record dir "null," + // has one line records "null)", // char set spliceSchemaWatcher.schemaName, TABLE_19, getResourceDirectory() + "tz_micro_order_date.csv", "\"", 0, BADDIR.getCanonicalPath())); ps.execute();//from w ww .j av a2s . c om ResultSet rs = methodWatcher .executeQuery(format("select * from %s.%s", spliceSchemaWatcher.schemaName, TABLE_19)); List<String> results = Lists.newArrayList(); while (rs.next()) { Timestamp order_date = rs.getTimestamp(1); assertNotNull("order_date incorrect", order_date); //have to deal with differing time zones here Assert.assertEquals("2013-04-21 09:21:24.980034", order_date.toString()); results.add(String.format("order_date:%s", order_date)); } Assert.assertTrue("import failed!", results.size() == 1); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastServiceStatsDailyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {/*from w ww . j a v a2 s.c o m*/ connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM SERVICE_STATS_LAST_DAILY_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 HH:00:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO SERVICE_STATS_LAST_DAILY_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 daily timestamp. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastServiceStatsHourlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {/* w ww.ja v a2 s .c om*/ connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM SERVICE_STATS_LAST_HOURLY_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 HH:mm:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO SERVICE_STATS_LAST_HOURLY_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 hourly timestamp. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastServiceStatsMonthlyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {/* w ww .j av a2 s . c o m*/ connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM SERVICE_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 SERVICE_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. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }
From source file:org.apache.stratos.usage.summary.helper.util.DataAccessObject.java
public String getAndUpdateLastCartridgeStatsDailyTimestamp() throws SQLException { Timestamp lastSummaryTs = null; Connection connection = null; try {//from www . ja va 2 s. c om connection = dataSource.getConnection(); String sql = "SELECT TIMESTMP FROM CARTRIDGE_STATS_LAST_DAILY_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 HH:00:00"); Timestamp currentTs = Timestamp.valueOf(formatter.format(new Date())); String currentSql = "INSERT INTO CARTRIDGE_STATS_LAST_DAILY_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 daily timestamp for cartridge stats. ", e); } finally { if (connection != null) { connection.close(); } } return lastSummaryTs.toString(); }