List of usage examples for java.sql PreparedStatement setTimestamp
void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException;
java.sql.Timestamp
value. From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
/** * The test inserts a few time partitioned datasets. A query is issued that retrieves the partitions older than 2 * years.// w w w .j a va2 s. com */ @Test public void testKeepLast2YearsOfDailyPartitions() throws Exception { insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2015/11/25")); //61 days insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2015/12/01")); // 55 days insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2014/11/21")); // 430 days insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2014/01/22")); // 733 days (more than 2 years) insertDailyPartition(new Path("/data/tracking/MetricEvent/daily/2013/01/25")); // 1095 days (more than 2 years) // Use the current timestamp for consistent test results. Timestamp currentTimestamp = new Timestamp( DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN).parseDateTime("2016/01/25").getMillis()); PreparedStatement statement = connection .prepareStatement("SELECT path FROM Daily_Partitions WHERE TIMESTAMP_DIFF(?, ts, 'Days') > ?"); statement.setTimestamp(1, currentTimestamp); statement.setLong(2, TWO_YEARS_IN_DAYS); ResultSet rs = statement.executeQuery(); // Daily partitions to be cleaned rs.next(); Assert.assertEquals(rs.getString(1), "/data/tracking/MetricEvent/daily/2014/01/22"); rs.next(); Assert.assertEquals(rs.getString(1), "/data/tracking/MetricEvent/daily/2013/01/25"); }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int[] batchInsert(final List<Plugin> plugins, final int sessionID, final int projectID) { final String SQL = "insert into RBT_RAW_DATA (plugin_id, session_id, " + "project_id, duration, event_time, plugin_key) values (?, ?, ?, ?, ?, ?)"; int[] updateCounts = jdbcTemplateObject.batchUpdate(SQL, new BatchPreparedStatementSetter() { public void setValues(PreparedStatement ps, int i) throws SQLException { ps.setInt(1, plugins.get(i).getId()); ps.setInt(2, sessionID);//from w ww .j a v a 2s . co m ps.setInt(3, projectID); ps.setLong(4, plugins.get(i).getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugins.get(i).getStartTime().getTime())); ps.setString(6, plugins.get(i).getGroupId() + ":" + plugins.get(i).getArtifactId()); } public int getBatchSize() { return plugins.size(); } }); return updateCounts; }
From source file:com.ccoe.build.dal.RawDataJDBCTemplate.java
public int create(final Plugin plugin, final int sessionID, final int projectID) { final String SQL = "insert into RBT_RAW_DATA (plugin_id, session_id, " + "project_id, duration, event_time, plugin_key) values (?, ?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplateObject.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(SQL, new String[] { "id" }); ps.setInt(1, plugin.getId()); ps.setInt(2, sessionID);/*from w w w . j a v a 2 s .co m*/ ps.setInt(3, projectID); ps.setLong(4, plugin.getDuration()); ps.setTimestamp(5, new java.sql.Timestamp(plugin.getStartTime().getTime())); ps.setString(6, plugin.getGroupId() + ":" + plugin.getArtifactId()); return ps; } }, keyHolder); return keyHolder.getKey().intValue(); }
From source file:net.solarnetwork.node.dao.jdbc.reactor.JdbcInstructionDao.java
@Override protected void setStoreStatementValues(Instruction instruction, PreparedStatement ps) throws SQLException { int col = 1;/*from www . ja v a2 s .c o m*/ ps.setTimestamp(col++, new java.sql.Timestamp(instruction.getInstructionDate().getTime())); ps.setString(col++, instruction.getRemoteInstructionId()); ps.setString(col++, instruction.getInstructorId()); ps.setString(col++, instruction.getTopic()); }
From source file:net.mindengine.oculus.frontend.service.project.build.JdbcBuildDAO.java
@Override public long createBuild(Build build) throws Exception { String sql = "insert into builds (name, description, date, project_id) values (?,?,?,?)"; PreparedStatement ps = getConnection().prepareStatement(sql); ps.setString(1, build.getName());/*from www .j a v a 2 s.co m*/ ps.setString(2, build.getDescription()); ps.setTimestamp(3, new Timestamp(build.getDate().getTime())); ps.setLong(4, build.getProjectId()); logger.info(ps); ps.execute(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getLong(1); } return 0; }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
private void insertDailyPartition(Path dailyPartitionPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(), Path.SEPARATOR + "daily"); DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN) .parseDateTime(StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR)); PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)"); insert.setString(1, datasetPath);// w w w.j a v a 2 s. c o m insert.setString(2, dailyPartitionPath.toString()); insert.setTimestamp(3, new Timestamp(partition.getMillis())); insert.executeUpdate(); }
From source file:iddb.web.security.dao.SessionDAO.java
public void insert(Session session) { String sql;//from w w w . ja va2s . c om sql = "insert into user_session (id, userid, ip, created) values (?,?,?,?)"; Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, session.getKey()); st.setLong(2, session.getUserId()); st.setString(3, session.getIp()); st.setTimestamp(4, new Timestamp(new Date().getTime())); st.executeUpdate(); } catch (SQLException e) { log.error("insert", e); } catch (IOException e) { log.error("insert", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:net.solarnetwork.node.dao.jdbc.AbstractJdbcDatumDao.java
/** * Mark a Datum as uploaded./*w w w .jav a2 s . c om*/ * * <p> * This method will execute the {@link #SQL_RESOURCE_UPDATE_UPLOADED} SQL * setting the following parameters: * </p> * * <ol> * <li>Timestamp parameter based on {@code timestamp}</li> * <li>Timestamp parameter based on {@code created}</li> * <li>Object parameter based on {@code id}</li> * </ol> * * @param created * the date the object was created * @param id * the object's source or location ID * @param timestamp * the date the upload happened */ protected void updateDatumUpload(final long created, final Object id, final long timestamp) { getJdbcTemplate().update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(getSqlResource(SQL_RESOURCE_UPDATE_UPLOADED)); int col = 1; ps.setTimestamp(col++, new java.sql.Timestamp(timestamp)); ps.setTimestamp(col++, new java.sql.Timestamp(created)); ps.setObject(col++, id); return ps; } }); }
From source file:fi.okm.mpass.shibboleth.profile.metadata.DataSourceMetadataResolverTest.java
protected void insertService(final DataSourceMetadataResolver resolver, final String entityId, final String acsUrl) throws Exception { final String insertResult = "INSERT INTO mpass_services" + " (samlEntityId, samlAcsUrl, startTime) VALUES (?,?,?)"; try (final Connection conn = resolver.getDataSource().getConnection()) { final PreparedStatement statement = conn.prepareStatement(insertResult, Statement.RETURN_GENERATED_KEYS); statement.setString(1, entityId); statement.setString(2, acsUrl);//from w w w.j a v a2 s.c o m statement.setTimestamp(3, new Timestamp(System.currentTimeMillis())); statement.executeUpdate(); } catch (Exception e) { throw e; } resolver.refresh(); }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
private void insertSnapshot(Path snapshotPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(snapshotPath.toString(), Path.SEPARATOR); String snapshotName = StringUtils.substringAfterLast(snapshotPath.toString(), Path.SEPARATOR); long ts = Long.parseLong(StringUtils.substringBefore(snapshotName, "-PT-")); long recordCount = Long.parseLong(StringUtils.substringAfter(snapshotName, "-PT-")); PreparedStatement insert = connection.prepareStatement("INSERT INTO Snapshots VALUES (?, ?, ?, ?, ?)"); insert.setString(1, datasetPath);/* w ww .j av a 2 s . c o m*/ insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }