Java Code Examples for java.sql.ResultSet#getTimestamp()
The following examples show how to use
java.sql.ResultSet#getTimestamp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppServiceDAO.java From cerberus-source with GNU General Public License v3.0 | 6 votes |
@Override public AppService loadFromResultSet(ResultSet rs) throws SQLException { String service = ParameterParserUtil.parseStringParam(rs.getString("srv.Service"), ""); String group = ParameterParserUtil.parseStringParam(rs.getString("srv.Group"), ""); String servicePath = ParameterParserUtil.parseStringParam(rs.getString("srv.ServicePath"), ""); String operation = ParameterParserUtil.parseStringParam(rs.getString("srv.Operation"), ""); String serviceRequest = ParameterParserUtil.parseStringParam(rs.getString("srv.ServiceRequest"), ""); String attachementURL = ParameterParserUtil.parseStringParam(rs.getString("srv.AttachementURL"), ""); String description = ParameterParserUtil.parseStringParam(rs.getString("srv.Description"), ""); String type = ParameterParserUtil.parseStringParam(rs.getString("srv.Type"), ""); String method = ParameterParserUtil.parseStringParam(rs.getString("srv.Method"), ""); String application = ParameterParserUtil.parseStringParam(rs.getString("srv.Application"), ""); String usrModif = rs.getString("srv.UsrModif"); String usrCreated = rs.getString("srv.UsrCreated"); Timestamp dateCreated = rs.getTimestamp("srv.DateCreated"); Timestamp dateModif = rs.getTimestamp("srv.DateModif"); String fileName = ParameterParserUtil.parseStringParam(rs.getString("srv.FileName"), ""); String kafkaTopic = ParameterParserUtil.parseStringParam(rs.getString("srv.kafkaTopic"), ""); String kafkaKey = ParameterParserUtil.parseStringParam(rs.getString("srv.kafkaKey"), ""); String kafkaFilterPath = ParameterParserUtil.parseStringParam(rs.getString("srv.kafkaFilterPath"), ""); String kafkaFilterValue = ParameterParserUtil.parseStringParam(rs.getString("srv.kafkaFilterValue"), ""); factoryAppService = new FactoryAppService(); return factoryAppService.create(service, type, method, application, group, serviceRequest, kafkaTopic, kafkaKey, kafkaFilterPath, kafkaFilterValue, description, servicePath, attachementURL, operation, usrCreated, dateCreated, usrModif, dateModif, fileName); }
Example 2
Source File: TestDAO.java From cerberus-source with GNU General Public License v3.0 | 6 votes |
private Test loadFromResultSet(ResultSet resultSet) throws SQLException { if (resultSet == null) { return null; } String test = resultSet.getString("tes.test") == null ? "" : resultSet.getString("tes.test"); String description = resultSet.getString("tes.description") == null ? "" : resultSet.getString("tes.description"); String active = resultSet.getString("tes.active") == null ? "" : resultSet.getString("tes.active"); String parentTest = resultSet.getString("tes.ParentTest"); String usrCreated = resultSet.getString("tes.UsrCreated"); Timestamp dateCreated = resultSet.getTimestamp("tes.DateCreated"); String usrModif = resultSet.getString("tes.UsrModif"); Timestamp dateModif = resultSet.getTimestamp("tes.DateModif"); return factoryTest.create(test, description, active, parentTest, usrCreated, dateCreated, usrModif, dateModif); }
Example 3
Source File: ConfigUsedLogDaoImpl.java From qconfig with MIT License | 5 votes |
@Override public ConfigUsedLog extractData(ResultSet rs) throws SQLException, DataAccessException { if (rs.next()) { return new ConfigUsedLog(rs.getString("group_id"), rs.getString("data_id"), rs.getString("profile"), rs.getString("source_group_id"), rs.getString("source_data_id"), rs.getString("source_profile"), rs.getString("ip"), rs.getInt("port"), rs.getInt("version"), ConfigUsedType.codeOf(rs.getInt("config_type")), rs.getString("consumer_profile"), rs.getString("remarks"), rs.getTimestamp("update_time")); } return null; }
Example 4
Source File: NestedWhiteboardDaoJdbc.java From OpenCue with Apache License 2.0 | 5 votes |
private static final NestedJob mapResultSetToJob(ResultSet rs) throws SQLException { NestedJob.Builder jobBuilder = NestedJob.newBuilder() .setId(rs.getString("pk_job")) .setLogDir(rs.getString("str_log_dir")) .setMaxCores(Convert.coreUnitsToCores(rs.getInt("int_max_cores"))) .setMinCores(Convert.coreUnitsToCores(rs.getInt("int_min_cores"))) .setName(rs.getString("str_name")) .setPriority(rs.getInt("int_priority")) .setShot(rs.getString("str_shot")) .setShow(rs.getString("str_show")) .setOs(rs.getString("str_os")) .setFacility(rs.getString("facility_name")) .setGroup(rs.getString("group_name")) .setState(JobState.valueOf(rs.getString("str_state"))) .setUser(rs.getString("str_user")) .setIsPaused(rs.getBoolean("b_paused")) .setHasComment(rs.getBoolean("b_comment")) .setAutoEat(rs.getBoolean("b_autoeat")) .setStartTime((int) (rs.getTimestamp("ts_started").getTime() / 1000)) .setStats(WhiteboardDaoJdbc.mapJobStats(rs)); int uid = rs.getInt("int_uid"); if (!rs.wasNull()) { jobBuilder.setUid(uid); } Timestamp ts = rs.getTimestamp("ts_stopped"); if (ts != null) { jobBuilder.setStopTime((int) (ts.getTime() / 1000)); } else { jobBuilder.setStopTime(0); } return jobBuilder.build(); }
Example 5
Source File: TestCaseStepActionExecutionDAO.java From cerberus-source with GNU General Public License v3.0 | 5 votes |
@Override public TestCaseStepActionExecution loadFromResultset(ResultSet resultSet) throws SQLException { long id = resultSet.getInt("exa.id"); String test = resultSet.getString("exa.test"); String testCase = resultSet.getString("exa.testcase"); int step = resultSet.getInt("exa.step"); int index = resultSet.getInt("exa.index"); int seq = resultSet.getInt("exa.sequence"); int sort = resultSet.getInt("exa.sort"); String returnCode = resultSet.getString("exa.returncode"); String returnMessage = resultSet.getString("exa.returnmessage"); String conditionOperator = resultSet.getString("exa.conditionOperator"); String conditionVal1Init = resultSet.getString("exa.ConditionVal1Init"); String conditionVal2Init = resultSet.getString("exa.ConditionVal2Init"); String conditionVal3Init = resultSet.getString("exa.ConditionVal3Init"); String conditionVal1 = resultSet.getString("exa.ConditionVal1"); String conditionVal2 = resultSet.getString("exa.ConditionVal2"); String conditionVal3 = resultSet.getString("exa.ConditionVal3"); String action = resultSet.getString("exa.action"); String value1 = resultSet.getString("exa.value1"); String value2 = resultSet.getString("exa.value2"); String value3 = resultSet.getString("exa.value3"); String value1Init = resultSet.getString("exa.value1Init"); String value2Init = resultSet.getString("exa.value2Init"); String value3Init = resultSet.getString("exa.value3Init"); String forceExeStatus = resultSet.getString("exa.forceExeStatus"); long start = resultSet.getTimestamp("exa.start") == null ? 0 : resultSet.getTimestamp("exa.start").getTime(); long end = resultSet.getTimestamp("exa.end") == null ? 0 : resultSet.getTimestamp("exa.end").getTime(); long startlong = resultSet.getLong("exa.startlong"); long endlong = resultSet.getLong("exa.endlong"); String description = resultSet.getString("exa.description"); return factoryTestCaseStepActionExecution.create(id, test, testCase, step, index, seq, sort, returnCode, returnMessage, conditionOperator, conditionVal1Init, conditionVal2Init, conditionVal3Init, conditionVal1, conditionVal2, conditionVal3, action, value1Init, value2Init, value3Init, value1, value2, value3, forceExeStatus, start, end, startlong, endlong, null, description, null, null); }
Example 6
Source File: DropTableWithViewsIT.java From phoenix with Apache License 2.0 | 5 votes |
public static void assertTaskColumns(Connection conn, String expectedStatus, PTable.TaskType taskType, String expectedTableName, String expectedTenantId, String expectedSchema, Timestamp expectedTs, String expectedIndexName) throws SQLException { ResultSet rs = conn.createStatement().executeQuery("SELECT * " + " FROM " + PhoenixDatabaseMetaData.SYSTEM_TASK_NAME + " WHERE " + PhoenixDatabaseMetaData.TASK_TYPE + " = " + taskType.getSerializedValue()); assertTrue(rs.next()); String taskStatus = rs.getString(PhoenixDatabaseMetaData.TASK_STATUS); assertEquals(expectedStatus, taskStatus); if (expectedTableName != null) { String tableName = rs.getString(PhoenixDatabaseMetaData.TABLE_NAME); assertEquals(expectedTableName, tableName); } if (expectedTenantId != null) { String tenantId = rs.getString(PhoenixDatabaseMetaData.TENANT_ID); assertEquals(expectedTenantId, tenantId); } if (expectedSchema != null) { String schema = rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM); assertEquals(expectedSchema, schema); } if (expectedTs != null) { Timestamp ts = rs.getTimestamp(PhoenixDatabaseMetaData.TASK_TS); assertEquals(expectedTs, ts); } if (expectedIndexName != null) { String data = rs.getString(PhoenixDatabaseMetaData.TASK_DATA); assertEquals(true, data.contains("\"IndexName\":\"" + expectedIndexName)); } }
Example 7
Source File: TradeDirect.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
private HoldingDataBean getHoldingDataFromResultSet(ResultSet rs) throws Exception { HoldingDataBean holdingData = null; holdingData = new HoldingDataBean(new Integer(rs.getInt("holdingID")), rs.getDouble("quantity"), rs.getBigDecimal("purchasePrice"), rs.getTimestamp("purchaseDate"), rs.getString("quote_symbol")); return holdingData; }
Example 8
Source File: DocumentFieldValueLoaders.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 5 votes |
@Override public Object retrieveFieldValue(final ResultSet rs, final boolean isDisplayColumnAvailable, final String adLanguage, final LookupDescriptor lookupDescriptor_NOTUSED) throws SQLException { final Timestamp valueTS = rs.getTimestamp(sqlColumnName); final java.util.Date value = valueTS == null ? null : new java.util.Date(valueTS.getTime()); return encrypted ? decrypt(value) : value; }
Example 9
Source File: LessonsSubNavBuilder.java From sakai with Educational Community License v2.0 | 5 votes |
private boolean isHidden(final ResultSet rs) throws SQLException { if (this.isInstructor) { return false; } if (rs.getInt("pageHidden") == 1) { return true; } else if (rs.getTimestamp("pageReleaseDate") != null) { if (rs.getTimestamp("pageReleaseDate").getTime() > System.currentTimeMillis()) { return true; } } return false; }
Example 10
Source File: AdminDAO.java From CodeDefenders with GNU Lesser General Public License v3.0 | 5 votes |
private static UserInfo userInfoFromRS(ResultSet rs) throws SQLException { final User user = UserDAO.userFromRS(rs); Timestamp ts = rs.getTimestamp("lastLogin"); final Role lastRole = Role.valueOrNull("lastRole"); final int totalScore = rs.getInt("TotalScore"); return new UserInfo(user, ts, lastRole, totalScore); }
Example 11
Source File: WhiteboardDaoJdbc.java From OpenCue with Apache License 2.0 | 5 votes |
public Job mapRow(ResultSet rs, int rowNum) throws SQLException { Job.Builder jobBuilder = Job.newBuilder() .setId(SqlUtil.getString(rs, "pk_job")) .setLogDir(SqlUtil.getString(rs, "str_log_dir")) .setMaxCores(Convert.coreUnitsToCores(rs.getInt("int_max_cores"))) .setMinCores(Convert.coreUnitsToCores(rs.getInt("int_min_cores"))) .setName(SqlUtil.getString(rs,"str_name")) .setPriority(rs.getInt("int_priority")) .setShot(SqlUtil.getString(rs,"str_shot")) .setShow(SqlUtil.getString(rs,"str_show")) .setFacility(SqlUtil.getString(rs,"facility_name")) .setGroup(SqlUtil.getString(rs,"group_name")) .setState(JobState.valueOf(SqlUtil.getString(rs,"str_state"))) .setUser(SqlUtil.getString(rs,"str_user")) .setIsPaused(rs.getBoolean("b_paused")) .setHasComment(rs.getBoolean("b_comment")) .setAutoEat(rs.getBoolean("b_autoeat")) .setStartTime((int) (rs.getTimestamp("ts_started").getTime() / 1000)) .setOs(SqlUtil.getString(rs,"str_os")); int uid = rs.getInt("int_uid"); if (!rs.wasNull()) { jobBuilder.setUid(uid); } Timestamp ts = rs.getTimestamp("ts_stopped"); if (ts != null) { jobBuilder.setStopTime((int) (ts.getTime() / 1000)); } else { jobBuilder.setStopTime(0); } jobBuilder.setJobStats(mapJobStats(rs)); return jobBuilder.build(); }
Example 12
Source File: DAOFactory.java From uavstack with Apache License 2.0 | 5 votes |
public Object getResult(ResultSet rs, String columnName) throws SQLException { Object sqlTimestamp = rs.getTimestamp(columnName); if (rs.wasNull()) { return null; } else { return sqlTimestamp; } }
Example 13
Source File: AbstractRDBValueIterator.java From phoebus with Eclipse Public License 1.0 | 4 votes |
/** Extract value from SQL result * @param result ResultSet that must contain contain time, severity, ..., value * @param handle_array Try to read array elements, or only a scalar value? * @return IValue Decoded IValue * @throws Exception on error, including cancellation */ protected VType decodeSampleTableValue(final ResultSet result, final boolean handle_array) throws Exception { // Get time stamp final java.sql.Timestamp stamp = result.getTimestamp(1); // Oracle has nanoseconds in TIMESTAMP, other RDBs in separate column if (reader.getPool().getDialect() != Dialect.Oracle) stamp.setNanos(result.getInt(7)); final Time time = TimeHelper.fromInstant(stamp.toInstant()); // Get severity/status final String status = reader.getStatus(result.getInt(3)); final AlarmSeverity severity = filterSeverity(reader.getSeverity(result.getInt(2)), status); final Alarm alarm = Alarm.of(severity, AlarmStatus.CLIENT, status); // Determine the value type // Try double final double dbl0 = result.getDouble(5); if (! result.wasNull()) { // Is it an error to have enumeration strings for double samples? // In here, we handle it by returning enumeration samples, // because the meta data would be wrong for double values. if (labels != null) return VEnum.of((int) dbl0, labels, alarm, time); // Double data. if (handle_array) { // Get array elements - if any. final double data[] = RDBPreferences.use_array_blob ? readBlobArrayElements(dbl0, result) : readArrayElements(time, dbl0, severity); if (data.length == 1) return VDouble.of(data[0], alarm, time, display); else return VDoubleArray.of(ArrayDouble.of(data), alarm, time, display); } else return VDouble.of(dbl0, alarm, time, display); } // Try integerRDBUtil final int num = result.getInt(4); if (! result.wasNull()) { // Enumerated integer? if (labels != null) return VEnum.of(num, labels, alarm, time); return VDouble.of(num, alarm, time, display); } // Default to string final String txt = result.getString(6); return VString.of(txt, alarm, time); }
Example 14
Source File: SnowflakeDriverIT.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
/** * SNOW-6290: timestamp value is shifted by local timezone */ @Test public void testSnow6290() throws Throwable { Connection connection = null; Statement statement = null; try { connection = getConnection(); statement = connection.createStatement(); // create test table statement.execute("CREATE OR REPLACE TABLE testSnow6290(ts timestamp)"); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO testSnow6290(ts) values(?)"); Timestamp ts = new Timestamp(System.currentTimeMillis()); preparedStatement.setTimestamp(1, ts); preparedStatement.executeUpdate(); ResultSet res = statement.executeQuery("select ts from testSnow6290"); assertTrue("expect a row", res.next()); Timestamp tsFromDB = res.getTimestamp(1); assertEquals("timestamp mismatch", ts.getTime(), tsFromDB.getTime()); } finally { if (statement != null) { statement.execute("DROP TABLE if exists testSnow6290"); statement.close(); } closeSQLObjects(statement, connection); } }
Example 15
Source File: TimestampSetterMapping.java From butterfly-persistence with Apache License 2.0 | 4 votes |
protected Object getValueFromResultSetDo(ResultSet result) throws SQLException { return result.getTimestamp(getColumnName()); }
Example 16
Source File: QuarkMetaResultSet.java From quark with Apache License 2.0 | 4 votes |
private static Object getValue(ResultSet resultSet, int type, int j, Calendar calendar) throws SQLException { switch (type) { case Types.BIGINT: final long aLong = resultSet.getLong(j + 1); return aLong == 0 && resultSet.wasNull() ? null : aLong; case Types.INTEGER: final int anInt = resultSet.getInt(j + 1); return anInt == 0 && resultSet.wasNull() ? null : anInt; case Types.SMALLINT: final short aShort = resultSet.getShort(j + 1); return aShort == 0 && resultSet.wasNull() ? null : aShort; case Types.TINYINT: final byte aByte = resultSet.getByte(j + 1); return aByte == 0 && resultSet.wasNull() ? null : aByte; case Types.DOUBLE: case Types.FLOAT: final double aDouble = resultSet.getDouble(j + 1); return aDouble == 0D && resultSet.wasNull() ? null : aDouble; case Types.REAL: final float aFloat = resultSet.getFloat(j + 1); return aFloat == 0D && resultSet.wasNull() ? null : aFloat; case Types.DATE: final Date aDate = resultSet.getDate(j + 1, calendar); return aDate == null ? null : (int) (aDate.getTime() / DateTimeUtils.MILLIS_PER_DAY); case Types.TIME: final Time aTime = resultSet.getTime(j + 1, calendar); return aTime == null ? null : (int) (aTime.getTime() % DateTimeUtils.MILLIS_PER_DAY); case Types.TIMESTAMP: final Timestamp aTimestamp = resultSet.getTimestamp(j + 1, calendar); return aTimestamp == null ? null : aTimestamp.getTime(); case Types.ARRAY: final Array array = resultSet.getArray(j + 1); if (null == array) { return null; } ResultSet arrayValues = array.getResultSet(); TreeMap<Integer, Object> map = new TreeMap<>(); while (arrayValues.next()) { // column 1 is the index in the array, column 2 is the value. // Recurse on `getValue` to unwrap nested types correctly. // `j` is zero-indexed and incremented for us, thus we have `1` being used twice. map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar)); } // If the result set is not in the same order as the actual Array, TreeMap fixes that. // Need to make a concrete list to ensure Jackson serialization. //return new ListLike<Object>(new ArrayList<>(map.values()), ListLikeType.ARRAY); return new ArrayList<>(map.values()); case Types.STRUCT: Struct struct = resultSet.getObject(j + 1, Struct.class); Object[] attrs = struct.getAttributes(); List<Object> list = new ArrayList<>(attrs.length); for (Object o : attrs) { list.add(o); } return list; default: return resultSet.getObject(j + 1); } }
Example 17
Source File: DalObjectRowMapper.java From dal with Apache License 2.0 | 4 votes |
public Timestamp convert(ResultSet rs, Object value) throws SQLException { return rs.getTimestamp(1);}
Example 18
Source File: TimestampArithTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
void checkResultRow(ResultSet rs, String sql) throws SQLException { java.sql.Timestamp actual = rs.getTimestamp(1); assertFalse("Unexpected null result from '" + sql + "'.", (rs.wasNull() || actual == null) && expected != null); assertFalse("Expected null result from '" + sql + "'.", !(rs.wasNull() || actual == null) && expected == null); assertEquals("Unexpected result from '" + sql + "'.", expected, actual); }
Example 19
Source File: SqlTimestampTypeHandler.java From tangyuan2 with GNU General Public License v3.0 | 4 votes |
@Override public Timestamp getNullableResult(ResultSet rs, String columnName) throws SQLException { return rs.getTimestamp(columnName); }
Example 20
Source File: ReportGenerator.java From freeacs with MIT License | 4 votes |
/** * Find the previous timestamp where reports have been made, then roll forward to next timestamp * to perform reporting. If the old timestamp is more than 2 days ago, then default to maximum 2 * days ago. If the old timestamp is null, default to 2 days ago. * * @param periodType * @param tablename * @return * @throws SQLException */ public Date startReportFromTms(PeriodType periodType, String tablename) throws SQLException { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; SQLException sqle = null; try { long now = System.currentTimeMillis(); long twoDaysAgo = now - 2L * 86400L * 1000L; connection = mainDataSource.getConnection(); DynamicStatement ds = new DynamicStatement(); ds.addSqlAndArguments( "select timestamp_ from " + tablename + " where period_type = " + periodType.getTypeInt() + " order by timestamp_ desc"); ps = ds.makePreparedStatement(connection); ps.setFetchSize(1); rs = ps.executeQuery(); if (rs.next()) { Timestamp tms = rs.getTimestamp("timestamp_"); if (tms != null) { Date nextTms = converter.rollForward(tms, periodType); while (nextTms.getTime() < twoDaysAgo) { nextTms = converter.rollForward(nextTms, periodType); } return nextTms; } } // if no data exists, start from two days ago return converter.convert(new Date(twoDaysAgo), periodType); } catch (SQLException sqlex) { sqle = sqlex; throw sqlex; } finally { if (rs != null) { rs.close(); } if (ps != null) { ps.close(); } if (connection != null) { connection.close(); } } }