List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:com.sfs.whichdoctor.dao.SpecialtyDAOImpl.java
/** * Load the specialty bean from the resultset. * * @param rs the rs//from w w w . j ava2s .c o m * @return the specialty bean * @throws SQLException the sQL exception */ private SpecialtyBean loadSpecialty(final ResultSet rs) throws SQLException { SpecialtyBean specialty = new SpecialtyBean(); specialty.setId(rs.getInt("SpecialtyId")); specialty.setGUID(rs.getInt("GUID")); specialty.setReferenceGUID(rs.getInt("ReferenceGUID")); specialty.setTrainingOrganisation(rs.getString("TrainingOrganisation")); specialty.setTrainingProgram(rs.getString("TrainingProgram")); specialty.setTrainingProgramYear(rs.getInt("TrainingProgramYear")); specialty.setMemo(rs.getString("Memo")); specialty.setStatus(rs.getString("SpecialtyStatus")); specialty.setIsbRole(1, rs.getString("ISBRole")); specialty.setIsbRole(2, rs.getString("SecondISBRole")); specialty.setIsbRole(3, rs.getString("ThirdISBRole")); specialty.setActive(rs.getBoolean("Active")); try { specialty.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing CreatedDate: " + sqe.getMessage()); } specialty.setCreatedBy(rs.getString("CreatedBy")); try { specialty.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage()); } specialty.setModifiedBy(rs.getString("ModifiedBy")); return specialty; }
From source file:edumsg.core.commands.dm.GetConversationsCommand.java
@Override public void execute() { ResultSet set = null; try {/*from w w w . ja v a2 s .c o m*/ dbConn = PostgresConnection.getDataSource().getConnection(); dbConn.setAutoCommit(false); proc = dbConn.prepareCall("{? = call get_conversations(?)}"); proc.setPoolable(true); proc.registerOutParameter(1, Types.OTHER); proc.setString(2, map.get("session_id")); proc.execute(); set = (ResultSet) proc.getObject(1); root.put("app", map.get("app")); root.put("method", map.get("method")); root.put("status", "ok"); root.put("code", "200"); ArrayList<Conversation> convs = new ArrayList<>(); while (set.next()) { int conv_id = set.getInt(1); int sender_id = set.getInt(2); String sender_name = set.getString(3); int reciever_id = set.getInt(4); String reciever_name = set.getString(5); String dm_text = set.getString(6); Timestamp created_at = set.getTimestamp(7); String sender_username = set.getString(8); String receiver_username = set.getString(9); String sender_avatar = set.getString(10); String receiver_avatar = set.getString(11); User sender = new User(); sender.setId(sender_id); sender.setName(sender_name); sender.setUsername(sender_username); sender.setAvatarUrl(sender_avatar); User reciever = new User(); reciever.setId(reciever_id); reciever.setName(reciever_name); reciever.setUsername(receiver_username); reciever.setAvatarUrl(receiver_avatar); Conversation conv = new Conversation(); conv.setId(conv_id); DirectMessage dm = new DirectMessage(); dm.setSender(sender); dm.setReciever(reciever); dm.setDmText(dm_text); dm.setCreatedAt(created_at); conv.setLastDM(dm); convs.add(conv); } ValueNode child = nf.pojoNode(convs); root.set("convs", child); try { CommandsHelp.submit(map.get("app"), mapper.writeValueAsString(root), map.get("correlation_id"), LOGGER); JSONObject cacheEntry = new JSONObject(mapper.writeValueAsString(root)); cacheEntry.put("cacheStatus", "valid"); TweetsCache.tweetCache.set("get_convs:" + map.getOrDefault("session_id", ""), cacheEntry.toString()); } catch (JsonGenerationException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (JsonMappingException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } dbConn.commit(); } catch (PSQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); LOGGER.log(Level.SEVERE, e.getMessage(), e); } catch (SQLException e) { CommandsHelp.handleError(map.get("app"), map.get("method"), e.getMessage(), map.get("correlation_id"), LOGGER); LOGGER.log(Level.SEVERE, e.getMessage(), e); } finally { PostgresConnection.disconnect(set, proc, dbConn); } }
From source file:com.sfs.whichdoctor.dao.IsbEntityDAOImpl.java
/** * Load isb entity.// w ww. ja v a 2s .co m * * @param rs the rs * * @return the isb entity bean * * @throws SQLException the SQL exception */ private IsbEntityBean loadIsbEntity(final ResultSet rs) throws SQLException { IsbEntityBean entity = new IsbEntityBean(); entity.setId(rs.getInt("Id")); entity.setGUID(rs.getInt("GUID")); entity.setIdentifier(rs.getString("Identifier")); entity.setName(rs.getString("Name")); entity.setTarget(rs.getString("Target")); entity.setObjectType(rs.getString("ObjectType")); entity.setActive(rs.getBoolean("Active")); try { entity.setCreatedDate(rs.getTimestamp("CreatedInternal")); } catch (SQLException e) { dataLogger.debug("Error reading CreatedInternal date: " + e.getMessage()); } try { entity.setModifiedDate(rs.getTimestamp("ModifiedInternal")); } catch (SQLException e) { dataLogger.debug("Error reading ModifiedInternal date: " + e.getMessage()); } try { entity.setExportedDate(rs.getTimestamp("ModifiedExternal")); } catch (SQLException e) { dataLogger.debug("Error reading ModifiedExternal date: " + e.getMessage()); } return entity; }
From source file:gobblin.metastore.database.DatabaseJobHistoryStoreV101.java
private JobExecutionInfo resultSetToJobExecutionInfo(ResultSet rs) throws SQLException { JobExecutionInfo jobExecutionInfo = new JobExecutionInfo(); jobExecutionInfo.setJobName(rs.getString("job_name")); jobExecutionInfo.setJobId(rs.getString("job_id")); try {/*from ww w . j a va 2 s .co m*/ Timestamp startTime = rs.getTimestamp("start_time"); if (startTime != null) { jobExecutionInfo.setStartTime(startTime.getTime()); } } catch (SQLException se) { jobExecutionInfo.setStartTime(0); } try { Timestamp endTime = rs.getTimestamp("end_time"); if (endTime != null) { jobExecutionInfo.setEndTime(endTime.getTime()); } } catch (SQLException se) { jobExecutionInfo.setEndTime(0); } jobExecutionInfo.setDuration(rs.getLong("duration")); String state = rs.getString("state"); if (!Strings.isNullOrEmpty(state)) { jobExecutionInfo.setState(JobStateEnum.valueOf(state)); } jobExecutionInfo.setLaunchedTasks(rs.getInt("launched_tasks")); jobExecutionInfo.setCompletedTasks(rs.getInt("completed_tasks")); String launcherType = rs.getString("launcher_type"); if (!Strings.isNullOrEmpty(launcherType)) { jobExecutionInfo.setLauncherType(LauncherTypeEnum.valueOf(launcherType)); } String trackingUrl = rs.getString("tracking_url"); if (!Strings.isNullOrEmpty(trackingUrl)) { jobExecutionInfo.setTrackingUrl(trackingUrl); } return jobExecutionInfo; }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
private User getUserFromResultSet(ResultSet rs) throws SQLException { User user = new User(); user.setId(rs.getInt(1));/*from w ww. jav a 2 s .c om*/ user.setUserName(rs.getString(2)); user.setEmail(rs.getString(3)); user.setPassword(rs.getString(4)); user.setOpen_date(rs.getDate(5)); user.setReceiveNewsletter(rs.getInt(6)); user.setConfirmEmailFlag(rs.getInt(7)); user.setConfirmEmailRandom(rs.getString(8)); user.setConfirmEmailDate(rs.getTimestamp(9)); return user; }
From source file:gobblin.metastore.database.DatabaseJobHistoryStoreV101.java
private TaskExecutionInfo resultSetToTaskExecutionInfo(ResultSet rs) throws SQLException { TaskExecutionInfo taskExecutionInfo = new TaskExecutionInfo(); taskExecutionInfo.setTaskId(rs.getString("task_id")); taskExecutionInfo.setJobId(rs.getString("job_id")); try {/*from ww w .java 2 s .c o m*/ Timestamp startTime = rs.getTimestamp("start_time"); if (startTime != null) { taskExecutionInfo.setStartTime(startTime.getTime()); } } catch (SQLException se) { taskExecutionInfo.setStartTime(0); } try { Timestamp endTime = rs.getTimestamp("end_time"); if (endTime != null) { taskExecutionInfo.setEndTime(endTime.getTime()); } } catch (SQLException se) { taskExecutionInfo.setEndTime(0); } taskExecutionInfo.setDuration(rs.getLong("duration")); String state = rs.getString("state"); if (!Strings.isNullOrEmpty(state)) { taskExecutionInfo.setState(TaskStateEnum.valueOf(state)); } String failureException = rs.getString("failure_exception"); if (!Strings.isNullOrEmpty(failureException)) { taskExecutionInfo.setFailureException(failureException); } taskExecutionInfo.setLowWatermark(rs.getLong("low_watermark")); taskExecutionInfo.setHighWatermark(rs.getLong("high_watermark")); Table table = new Table(); String namespace = rs.getString("table_namespace"); if (!Strings.isNullOrEmpty(namespace)) { table.setNamespace(namespace); } String name = rs.getString("table_name"); if (!Strings.isNullOrEmpty(name)) { table.setName(name); } String type = rs.getString("table_type"); if (!Strings.isNullOrEmpty(type)) { table.setType(TableTypeEnum.valueOf(type)); } taskExecutionInfo.setTable(table); return taskExecutionInfo; }
From source file:edu.arizona.kra.proposaldevelopment.dao.ojb.PropDevRoutingStateDaoOjb.java
@Override public List<ProposalDevelopmentRoutingState> getPropDevRoutingState(Map<String, String> searchCriteria) throws SQLException, LookupException { List<ProposalDevelopmentRoutingState> results = new ArrayList<ProposalDevelopmentRoutingState>(); HashSet<String> resultDocNumbers = new HashSet<String>(); LOG.debug("getPropDevRoutingState searchCriteria={}", searchCriteria); String sqlQuery = buildSqlQuery(searchCriteria); boolean displayAdHocNodes = (searchCriteria.containsKey(ROUTE_STOP_NAME) && StringUtils.isEmpty(searchCriteria.get(ROUTE_STOP_NAME))); try (DBConnection dbc = new DBConnection(this.getPersistenceBroker(true))) { ResultSet rs = dbc.executeQuery(sqlQuery, null); while (rs.next()) { String documentNumber = rs.getString(COL_DOCUMENT_NUMBER); String annotation = rs.getString(COL_ANNOTATION); //avoid displaying more than one result row per document if (!resultDocNumbers.contains(documentNumber)) { //skip AdHoc nodes if the searchCriteria has a specific NodeName if (isAdHocNode(annotation) && !displayAdHocNodes) { continue; }//from ww w . j a va 2 s. c o m ProposalDevelopmentRoutingState rtState = new ProposalDevelopmentRoutingState(); rtState.setRouteStopDate(rs.getTimestamp(COL_STOP_DATE)); rtState.setRouteStopName(getRouteStopLabel(rs.getString(COL_NODE_NAME), annotation)); rtState.setProposalNumber(rs.getString(COL_PROPOSAL_NUMBER)); rtState.setProposalDocumentNumber(documentNumber); rtState.setProposalTitle(rs.getString(COL_PROPOSAL_TITLE)); rtState.setSponsorName(rs.getString(COL_SPONSOR_NAME)); rtState.setSponsorCode(rs.getString(COL_SPONSOR_CODE)); rtState.setSponsorDeadlineDate(rs.getDate(COL_SPONSOR_DEADLINE_DATE)); rtState.setSponsorDeadlineTime(rs.getString(COL_SPONSOR_DEADLINE_TIME)); rtState.setPrincipalInvestigatorName(rs.getString(COL_PRINCIPAL_INVESTIGATOR)); rtState.setLeadUnitNumber(rs.getString(COL_LEAD_UNIT)); rtState.setLeadUnitName(rs.getString(COL_LEAD_UNIT_NAME)); rtState.setLeadCollege(""); String ordExpedited = rs.getString(COL_ORD_EXP); rtState.setORDExpedited(YES.equalsIgnoreCase(ordExpedited)); String fpr = rs.getString(COL_FPR); rtState.setFinalProposalReceived(YES.equalsIgnoreCase(fpr)); rtState.setSPSPersonId(rs.getString(COL_SPS_REVIEWER_ID)); rtState.setSPSReviewerName(rs.getString(COL_SPS_REVIEWER_NAME)); results.add(rtState); resultDocNumbers.add(rtState.getProposalDocumentNumber()); } } } catch (SQLException sqle) { LOG.error("SQLException: " + sqle.getMessage(), sqle); throw sqle; } catch (LookupException le) { LOG.error("LookupException: " + le.getMessage(), le); throw le; } LOG.debug("getPropDevRoutingState: no of unfiltered results={}.", results.size()); //perform additional filtering on the results if the user specified a workflow unit if (!results.isEmpty() && searchCriteria.containsKey(WORKFLOW_UNIT) && StringUtils.isNotEmpty(searchCriteria.get(WORKFLOW_UNIT))) { String workflowUnit = searchCriteria.get(WORKFLOW_UNIT); List<String> workFlowUnits = findWorkflowUnitNumbers(workflowUnit); List<String> proposalNumbers = findProposalsForWorkflowUnits(workFlowUnits); List<ProposalDevelopmentRoutingState> filteredResults = new ArrayList<ProposalDevelopmentRoutingState>(); for (ProposalDevelopmentRoutingState rtState : results) { if (proposalNumbers.contains(rtState.getProposalNumber())) { filteredResults.add(rtState); } } LOG.debug("getPropDevRoutingState: filtered results={}.", filteredResults.size()); return filteredResults; } return results; }
From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java
public Transaction getTransaction(long id) throws SQLException { Connection connection = getConnection(); PreparedStatement statement = null; try {//from w ww . j a v a 2s. c om statement = connection.prepareStatement(GET_ACCOUNTOPERATIONS_STATEMENT); statement.setLong(1, id); ResultSet rs = statement.executeQuery(); if (rs.next()) { Transaction transaction = new Transaction(); if (rs.getInt(3) != ACCOUNT_OPERATION_PAYMENT) { return null; } transaction.setId(id); transaction.setSource_user_id(rs.getInt(6)); transaction.setDestination_user_id(rs.getInt(7)); transaction.setDate(rs.getTimestamp(5)); transaction.setAmount(rs.getLong(4)); return transaction; } else { return null; } } catch (SQLException e) { throw e; } finally { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
@Override public SchemaSet getSchemaSet(int id) { String sql = "select * from T_SCHEMA_SET where SCHEMA_SET_ID = :id"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("id", id); SchemaSet result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<SchemaSet>() { @Override/*from w w w .j a va 2 s . c o m*/ public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return result; }
From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java
@Override public SchemaSet getSchemaSet(String identifier, boolean workingCopy) { String sql = "select * from T_SCHEMA_SET where IDENTIFIER = :identifier and WORKING_COPY = :workingCopy"; Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("identifier", identifier); parameters.put("workingCopy", workingCopy); SchemaSet result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<SchemaSet>() { @Override/* www. j av a 2 s . com*/ public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException { SchemaSet ss = new SchemaSet(); ss.setId(rs.getInt("SCHEMA_SET_ID")); ss.setIdentifier(rs.getString("IDENTIFIER")); ss.setContinuityId(rs.getString("CONTINUITY_ID")); ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS"))); ss.setWorkingCopy(rs.getBoolean("WORKING_COPY")); ss.setWorkingUser(rs.getString("WORKING_USER")); ss.setDateModified(rs.getTimestamp("DATE_MODIFIED")); ss.setUserModified(rs.getString("USER_MODIFIED")); ss.setComment(rs.getString("COMMENT")); ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID")); ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED")); return ss; } }); return result; }