List of usage examples for java.sql ResultSet getDate
java.sql.Date getDate(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Date
object in the Java programming language. From source file:org.apache.hadoop.hive.jdbc.TestJdbcDriver.java
private void assertPreparedStatementResultAsExpected(ResultSet res) throws SQLException { assertNotNull(res);//from ww w.jav a2 s . c o m while (res.next()) { assertEquals("2011-03-25", res.getString("ddate")); assertEquals("10", res.getString("num")); assertEquals((byte) 10, res.getByte("num")); assertEquals("2011-03-25", res.getDate("ddate").toString()); assertEquals(Double.valueOf(10).doubleValue(), res.getDouble("num"), 0.1); assertEquals(10, res.getInt("num")); assertEquals(Short.valueOf("10").shortValue(), res.getShort("num")); assertEquals(10L, res.getLong("num")); assertEquals(true, res.getBoolean("bv")); Object o = res.getObject("ddate"); assertNotNull(o); o = res.getObject("num"); assertNotNull(o); } res.close(); assertTrue(true); }
From source file:eionet.meta.dao.mysql.VocabularyConceptDAOImpl.java
@Override public List<VocabularyConcept> getValidConceptsWithValuedElements(int vocabularyId, String conceptIdentifier, String label, String dataElementIdentifier, String language, String defaultLanguage) { Map<String, Object> params = new HashMap<String, Object>(); params.put("vocabularyId", vocabularyId); params.put("acceptedStatus", StandardGenericStatus.ACCEPTED.getValue()); StringBuilder sql = new StringBuilder(); sql.append(//from ww w. j a v a 2s .c o m "select distinct c.VOCABULARY_CONCEPT_ID, v.DATAELEM_ID, v.ELEMENT_VALUE, v.LANGUAGE, v.RELATED_CONCEPT_ID, "); sql.append("d.IDENTIFIER AS ELEMIDENTIFIER, a.VALUE as DATATYPE, c.VOCABULARY_ID, c.IDENTIFIER, c.LABEL, "); sql.append("c.DEFINITION, c.NOTATION, c.STATUS, c.ACCEPTED_DATE, c.NOT_ACCEPTED_DATE, c.STATUS_MODIFIED, "); sql.append( "rcvs.IDENTIFIER as RVOCSETIDENTIFIER, rcv.IDENTIFIER as RVOCIDENTIFIER, rcv.BASE_URI as RVOCBASE_URI, "); sql.append("rc.IDENTIFIER AS RCONCEPTIDENTIFIER, rc.LABEL as RCONCEPTLABEL "); sql.append("from VOCABULARY_CONCEPT c "); sql.append("left join VOCABULARY_CONCEPT_ELEMENT v on v.VOCABULARY_CONCEPT_ID = c.VOCABULARY_CONCEPT_ID "); sql.append("LEFT JOIN DATAELEM d ON (v.DATAELEM_ID = d.DATAELEM_ID) "); sql.append("LEFT JOIN VOCABULARY_CONCEPT rc on v.RELATED_CONCEPT_ID = rc.VOCABULARY_CONCEPT_ID "); sql.append("LEFT JOIN VOCABULARY rcv ON rc.VOCABULARY_ID = rcv.VOCABULARY_ID "); sql.append("LEFT JOIN VOCABULARY_SET rcvs ON (rcv.FOLDER_ID = rcvs.ID ) "); sql.append("left join (ATTRIBUTE a, M_ATTRIBUTE ma) on (a.DATAELEM_ID = d.DATAELEM_ID "); sql.append("and PARENT_TYPE = 'E' and a.M_ATTRIBUTE_ID = ma.M_ATTRIBUTE_ID and ma.NAME='Datatype') "); sql.append("where c.VOCABULARY_ID = :vocabularyId AND c.STATUS & :acceptedStatus = :acceptedStatus "); if (StringUtils.isNotBlank(conceptIdentifier)) { sql.append(" AND LOWER(c.IDENTIFIER) LIKE LOWER(:conceptIdentifier)"); params.put("conceptIdentifier", conceptIdentifier + "%"); } if (StringUtils.isNotBlank(label)) { sql.append(" AND (LOWER(c.LABEL) LIKE LOWER(:label) OR "); sql.append(" (d.IDENTIFIER LIKE :skosPrefLabel AND LOWER(ELEMENT_VALUE) LIKE LOWER(:label))) "); params.put("label", label + "%"); params.put("skosPrefLabel", "skos:prefLabel"); } if (StringUtils.isNotBlank(dataElementIdentifier)) { sql.append(" AND (d.IDENTIFIER LIKE :dataElementIdentifier "); if (StringUtils.isNotBlank(label)) { sql.append("OR d.IDENTIFIER LIKE :skosPrefLabel"); } sql.append(" ) "); params.put("dataElementIdentifier", StringUtils.trimToEmpty(dataElementIdentifier)); } if (StringUtils.isNotBlank(language)) { sql.append(" AND v.LANGUAGE in (:language, :defaultLanguage) "); params.put("language", StringUtils.trimToEmpty(language)); params.put("defaultLanguage", defaultLanguage); } sql.append("ORDER by c.VOCABULARY_CONCEPT_ID, v.DATAELEM_ID, d.IDENTIFIER, v.LANGUAGE, rcv.IDENTIFIER "); final List<VocabularyConcept> resultList = new ArrayList<VocabularyConcept>(); getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowCallbackHandler() { int previousConceptId = -1; int previousElemId = -1; VocabularyConcept vc; List<DataElement> oneElementValues; List<List<DataElement>> elementValues; @Override public void processRow(ResultSet rs) throws SQLException { int conceptId = rs.getInt("VOCABULARY_CONCEPT_ID"); // concept changed: if (conceptId != previousConceptId) { vc = new VocabularyConcept(); vc.setId(conceptId); vc.setLabel(rs.getString("LABEL")); vc.setIdentifier(rs.getString("IDENTIFIER")); vc.setDefinition(rs.getString("DEFINITION")); vc.setNotation(rs.getString("NOTATION")); vc.setStatus(rs.getInt("STATUS")); vc.setAcceptedDate(rs.getDate("ACCEPTED_DATE")); vc.setNotAcceptedDate(rs.getDate("NOT_ACCEPTED_DATE")); vc.setStatusModified(rs.getDate("STATUS_MODIFIED")); elementValues = new ArrayList<List<DataElement>>(); vc.setElementAttributes(elementValues); resultList.add(vc); } int elemId = rs.getInt("DATAELEM_ID"); if (elemId != previousElemId || conceptId != previousConceptId) { oneElementValues = new ArrayList<DataElement>(); elementValues.add(oneElementValues); } if (elemId > 0) { DataElement elem = new DataElement(); elem.setId(elemId); elem.setIdentifier(rs.getString("ELEMIDENTIFIER")); elem.setAttributeLanguage(rs.getString("LANGUAGE")); elem.setAttributeValue(rs.getString("ELEMENT_VALUE")); Integer relatedConceptId = rs.getInt("RELATED_CONCEPT_ID"); if (relatedConceptId != 0) { elem.setRelatedConceptId(relatedConceptId); elem.setRelatedConceptVocSet(rs.getString("RVOCSETIDENTIFIER")); elem.setRelatedConceptVocabulary(rs.getString("RVOCIDENTIFIER")); elem.setRelatedConceptIdentifier(rs.getString("RCONCEPTIDENTIFIER")); elem.setRelatedConceptLabel(rs.getString("RCONCEPTLABEL")); elem.setRelatedConceptBaseURI(rs.getString("RVOCBASE_URI")); } // add Datatype - is used in RDF output String dataType = rs.getString("DATATYPE"); if (dataType != null) { Map<String, List<String>> elemAttributeValues = new HashMap<String, List<String>>(); List<String> elemDatatypeValues = new ArrayList<String>(); elemDatatypeValues.add(dataType); elemAttributeValues.put("Datatype", elemDatatypeValues); elem.setElemAttributeValues(elemAttributeValues); } oneElementValues.add(elem); } previousConceptId = conceptId; previousElemId = elemId; } }); return resultList; }
From source file:eionet.meta.dao.mysql.VocabularyConceptDAOImpl.java
/** * {@inheritDoc}/*from w w w . ja va2s . com*/ */ @Override public VocabularyConceptResult searchVocabularyConcepts(VocabularyConceptFilter filter) { Map<String, Object> params = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); sql.append( "select SQL_CALC_FOUND_ROWS c.VOCABULARY_CONCEPT_ID, c.VOCABULARY_ID, c.IDENTIFIER, c.LABEL, c.DEFINITION, "); sql.append( "c.NOTATION, c.STATUS, c.ACCEPTED_DATE, c.NOT_ACCEPTED_DATE, c.STATUS_MODIFIED, v.LABEL AS VOCABULARY_LABEL, "); sql.append("v.IDENTIFIER AS VOCABULARY_IDENTIFIER, s.ID AS VOCSET_ID, s.LABEL as VOCSET_LABEL, "); sql.append("s.IDENTIFIER as VOCSET_IDENTIFIER "); sql.append("from VOCABULARY_CONCEPT c, VOCABULARY v, VOCABULARY_SET s "); sql.append("where v.VOCABULARY_ID = c.VOCABULARY_ID AND v.FOLDER_ID = s.ID "); if (filter.getVocabularyFolderId() > 0) { params.put("vocabularyFolderId", filter.getVocabularyFolderId()); sql.append("and c.VOCABULARY_ID=:vocabularyFolderId "); } if (StringUtils.isNotEmpty(filter.getText())) { if (filter.isWordMatch()) { params.put("text", "[[:<:]]" + filter.getText() + "[[:>:]]"); sql.append("and (c.NOTATION REGEXP :text "); sql.append("or c.LABEL REGEXP :text "); sql.append("or c.DEFINITION REGEXP :text "); sql.append("or c.IDENTIFIER REGEXP :text) "); // word match overrides exactmatch as it contains also exact matches } else if (filter.isExactMatch()) { params.put("text", filter.getText()); sql.append("and (c.NOTATION = :text "); sql.append("or c.LABEL = :text "); sql.append("or c.DEFINITION = :text "); sql.append("or c.IDENTIFIER = :text) "); } else { params.put("text", "%" + filter.getText() + "%"); sql.append("and (c.NOTATION like :text "); sql.append("or c.LABEL like :text "); sql.append("or c.DEFINITION like :text "); sql.append("or c.IDENTIFIER like :text) "); } } if (StringUtils.isNotEmpty(filter.getIdentifier())) { params.put("identifier", filter.getIdentifier()); sql.append("and c.IDENTIFIER = :identifier "); } if (StringUtils.isNotEmpty(filter.getDefinition())) { params.put("definition", filter.getDefinition()); sql.append("and c.DEFINITION = :definition "); } if (StringUtils.isNotEmpty(filter.getLabel())) { params.put("label", filter.getLabel()); sql.append("and c.LABEL = :label "); } if (filter.getExcludedIds() != null && !filter.getExcludedIds().isEmpty()) { params.put("excludedIds", filter.getExcludedIds()); sql.append("and c.VOCABULARY_CONCEPT_ID not in (:excludedIds) "); } if (filter.getIncludedIds() != null && !filter.getIncludedIds().isEmpty()) { params.put("includedIds", filter.getIncludedIds()); sql.append("and c.VOCABULARY_CONCEPT_ID in (:includedIds) "); } if (filter.getConceptStatus() != null) { params.put("conceptStatus", filter.getConceptStatus().getValue()); sql.append("and c.STATUS & :conceptStatus = :conceptStatus "); } if (StringUtils.isNotEmpty(filter.getVocabularyText())) { if (filter.isExactMatch()) { params.put("vocabularyText", filter.getVocabularyText()); sql.append("and (v.IDENTIFIER = :vocabularyText "); sql.append("or v.LABEL = :vocabularyText) "); } else { params.put("vocabularyText", "%" + filter.getVocabularyText() + "%"); sql.append("and (v.IDENTIFIER like :vocabularyText "); sql.append("or v.LABEL like :vocabularyText) "); } } if (filter.getExcludedVocabularySetIds() != null && filter.getExcludedVocabularySetIds().size() > 0) { params.put("excludedVocSetIds", filter.getExcludedVocabularySetIds()); sql.append("AND s.ID NOT IN (:excludedVocSetIds) "); } if (filter.isOrderByConceptId()) { sql.append("order by c.VOCABULARY_CONCEPT_ID"); } else if (filter.isNumericIdentifierSorting()) { sql.append("order by c.IDENTIFIER + 0 "); } else { sql.append("order by c.IDENTIFIER "); } if (filter.isUsePaging()) { sql.append("LIMIT ").append(filter.getOffset()).append(",").append(filter.getPageSize()); } List<VocabularyConcept> resultList = getNamedParameterJdbcTemplate().query(sql.toString(), params, new RowMapper<VocabularyConcept>() { @Override public VocabularyConcept mapRow(ResultSet rs, int rowNum) throws SQLException { VocabularyConcept vc = new VocabularyConcept(); vc.setId(rs.getInt("VOCABULARY_CONCEPT_ID")); vc.setVocabularyId(rs.getInt("VOCABULARY_ID")); vc.setIdentifier(rs.getString("IDENTIFIER")); vc.setLabel(rs.getString("LABEL")); vc.setDefinition(rs.getString("DEFINITION")); vc.setNotation(rs.getString("NOTATION")); vc.setStatus(rs.getInt("STATUS")); vc.setAcceptedDate(rs.getDate("ACCEPTED_DATE")); vc.setNotAcceptedDate(rs.getDate("NOT_ACCEPTED_DATE")); vc.setStatusModified(rs.getDate("STATUS_MODIFIED")); vc.setVocabularyIdentifier(rs.getString("VOCABULARY_IDENTIFIER")); vc.setVocabularyLabel(rs.getString("VOCABULARY_LABEL")); vc.setVocabularySetLabel(rs.getString("VOCSET_LABEL")); vc.setVocabularySetId(rs.getInt("VOCSET_ID")); vc.setVocabularySetIdentifier("VOCSET_IDENTIFIER"); return vc; } }); String totalSql = "SELECT FOUND_ROWS()"; int totalItems = getJdbcTemplate().queryForInt(totalSql); VocabularyConceptResult result = new VocabularyConceptResult(resultList, totalItems, filter); return result; }
From source file:at.alladin.rmbt.statisticServer.UsageJSONResource.java
/** * Returns the statistics for used versions for a specific timespan [begin, end) * @param begin select all tests with time >= begin * @param end select all tests with time < end * @return the structurized JSON object//from w w w . j a v a 2 s . c o m * @throws SQLException * @throws JSONException */ private JSONObject getVersions(String platform, Timestamp begin, Timestamp end) throws SQLException, JSONException { JSONObject returnObj = new JSONObject(); JSONArray sums = new JSONArray(); JSONArray values = new JSONArray(); returnObj.put("sums", sums); returnObj.put("values", values); HashMap<String, Long> fieldSums = new HashMap<>(); PreparedStatement ps; ResultSet rs; final String sql = "SELECT date_trunc('day', time) _day, COALESCE(client_software_version,'null') \"version\", count(client_software_version) count_version" + " FROM test" + " WHERE status='FINISHED' AND deleted=false AND time >= ? AND time < ? AND plattform = ?" + " GROUP BY _day, client_software_version " + " HAVING count(client_software_version) > 0 " + " ORDER BY _day ASC"; ps = conn.prepareStatement(sql); ps.setTimestamp(1, begin); ps.setTimestamp(2, end); ps.setString(3, platform); rs = ps.executeQuery(); //one array-item for each day long currentTime = -1; JSONObject currentEntry = null; JSONArray currentEntryValues = null; while (rs.next()) { //new item, of a new day is reached long newTime = rs.getDate("_day").getTime(); if (currentTime != newTime) { currentTime = newTime; currentEntry = new JSONObject(); currentEntryValues = new JSONArray(); currentEntry.put("day", rs.getDate("_day").getTime()); currentEntry.put("values", currentEntryValues); values.put(currentEntry); } //disable null-values String version = rs.getString("version"); long count = rs.getLong("count_version"); if (version.isEmpty()) { version = "empty"; } //add value to sum if (!fieldSums.containsKey(version)) { fieldSums.put(version, new Long(0)); } fieldSums.put(version, fieldSums.get(version) + count); JSONObject current = new JSONObject(); current.put("field", version); current.put("value", count); currentEntryValues.put(current); } rs.close(); ps.close(); //add field sums for (String field : fieldSums.keySet()) { JSONObject obj = new JSONObject(); obj.put("field", field); obj.put("sum", fieldSums.get(field)); sums.put(obj); } return returnObj; }
From source file:com.sfs.whichdoctor.dao.ReimbursementDAOImpl.java
/** * Load reimbursement.// w w w .j a v a2 s . c o m * * @param rs the rs * @param loadDetails the load details * * @return the reimbursement bean * * @throws SQLException the SQL exception */ private ReimbursementBean loadReimbursement(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { ReimbursementBean reimbursement = new ReimbursementBean(); reimbursement.setId(rs.getInt("ReimbursementId")); reimbursement.setGUID(rs.getInt("GUID")); reimbursement.setAbbreviation(rs.getString("Abbreviation")); reimbursement.setClassName(rs.getString("ReimbursementClass")); reimbursement.setTypeName(rs.getString("ReimbursementType")); reimbursement.setNumber(rs.getString("ReimbursementNo")); reimbursement.setDescription(rs.getString("Description")); reimbursement.setLocation(rs.getString("Location")); try { reimbursement.setMeetingDate(rs.getDate("MeetingDate")); } catch (SQLException e) { reimbursement.setMeetingDate(null); } reimbursement.setPersonId(rs.getInt("PersonId")); if (reimbursement.getPersonId() > 0) { PersonBean person = new PersonBean(); person.setGUID(reimbursement.getPersonId()); person.setPersonIdentifier(rs.getInt("PersonIdentifier")); person.setPreferredName(rs.getString("PreferredName")); person.setFirstName(rs.getString("FirstName")); person.setLastName(rs.getString("LastName")); person.setTitle(rs.getString("Title")); person.setGender(rs.getString("Gender")); // Load address. if (loadDetails.getBoolean("ADDRESS")) { try { person.setAddress(this.getAddressDAO().load(person.getGUID(), false, loadDetails.getString("ADDRESS_CLASS"), loadDetails.getString("ADDRESS_TYPE"))); } catch (Exception e) { dataLogger.error("Error loading address for reimbursement: " + e.getMessage()); } } reimbursement.setPerson(person); } reimbursement.setOrganisationId(rs.getInt("OrganisationId")); if (reimbursement.getOrganisationId() > 0) { OrganisationBean organisation = new OrganisationBean(); organisation.setGUID(reimbursement.getOrganisationId()); organisation.setName(rs.getString("OrganisationName")); if (loadDetails.getBoolean("ADDRESS")) { try { organisation.setAddress(this.getAddressDAO().load(organisation.getGUID(), false, loadDetails.getString("ADDRESS_CLASS"), loadDetails.getString("ADDRESS_TYPE"))); } catch (Exception e) { dataLogger.error("Error loading address for reimbursement: " + e.getMessage()); } } reimbursement.setOrganisation(organisation); } try { reimbursement.setIssued(rs.getDate("Issued")); } catch (SQLException e) { reimbursement.setIssued(null); } reimbursement.setValue(rs.getDouble("ReimbursementValue")); reimbursement.setNetValue(rs.getDouble("ReimbursementTotalValue")); reimbursement.setCancelled(rs.getBoolean("Cancelled")); reimbursement.setSecurity(rs.getString("Security")); if (loadDetails.getBoolean("EXPENSECLAIM")) { try { reimbursement.setExpenseClaims(this.expenseClaimDAO.load(reimbursement.getGUID(), loadDetails.getBoolean("EXPENSECLAIM_FULL"))); } catch (Exception e) { dataLogger.error("Error loading expense claims for reimbursement: " + e.getMessage()); } } reimbursement.setActive(rs.getBoolean("Active")); if (loadDetails.getBoolean("HISTORY")) { try { reimbursement.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } reimbursement.setCreatedBy(rs.getString("CreatedBy")); try { reimbursement.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } reimbursement.setModifiedBy(rs.getString("ModifiedBy")); try { reimbursement.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } reimbursement.setExportedBy(rs.getString("ExportedBy")); } if (loadDetails.getBoolean("TAGS")) { try { reimbursement.setTags( this.getTagDAO().load(reimbursement.getGUID(), loadDetails.getString("USERDN"), true)); } catch (Exception e) { dataLogger.error("Error loading tags for reimbursement: " + e.getMessage()); } } if (loadDetails.getBoolean("MEMO")) { try { reimbursement.setMemo( this.getMemoDAO().load(reimbursement.getGUID(), loadDetails.getBoolean("MEMO_FULL"))); } catch (Exception e) { dataLogger.error("Error loading memos for reimbursement: " + e.getMessage()); } } if (loadDetails.getBoolean("GROUPS")) { reimbursement.setGroups(loadGroups(reimbursement.getGUID())); } if (loadDetails.getBoolean("CREATED")) { UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); reimbursement.setCreatedUser(user); } if (loadDetails.getBoolean("MODIFIED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ModifiedBy")); user.setPreferredName(rs.getString("ModifiedFirstName")); user.setLastName(rs.getString("ModifiedLastName")); reimbursement.setModifiedUser(user); } if (loadDetails.getBoolean("EXPORTED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ExportedBy")); user.setPreferredName(rs.getString("ExportedFirstName")); user.setLastName(rs.getString("ExportedLastName")); reimbursement.setExportedUser(user); } return reimbursement; }
From source file:edu.ku.brc.specify.toycode.mexconabio.AnalysisBase.java
/** * @param refRow/*ww w .jav a 2 s . co m*/ * @param rs * @throws SQLException */ public void fillMichRow(final Object[] refRow, final ResultSet rs) throws SQLException { String catNum = rs.getString(1); String collectorNum = rs.getString(2); String collector = rs.getString(3); String genus = rs.getString(4); String species = rs.getString(5); String subspecies = rs.getString(6); String locality = rs.getString(7); Date collDate = rs.getDate(8); String country = rs.getString(9); String state = rs.getString(10); int year; int mon; int day; if (collDate != null) { cal.setTime(collDate); year = cal.get(Calendar.YEAR); mon = cal.get(Calendar.MONTH) + 1; day = cal.get(Calendar.DAY_OF_MONTH); } else { year = 0; mon = 0; day = 0; } refRow[CATNUM_INX] = catNum; refRow[COLNUM_INX] = collectorNum; refRow[GENUS_INX] = genus; refRow[SPECIES_INX] = species; refRow[SUBSPECIES_INX] = subspecies; refRow[COLLECTOR_INX] = collector; refRow[LOCALITY_INX] = locality; refRow[LATITUDE_INX] = null; refRow[LONGITUDE_INX] = null; refRow[YEAR_INX] = year > 0 ? Integer.toString(year) : null; refRow[MON_INX] = year > 0 ? Integer.toString(mon) : null; refRow[DAY_INX] = year > 0 ? Integer.toString(day) : null; refRow[COUNTRY_INX] = country; refRow[STATE_INX] = state; refRow[INST_INX] = "MICH"; for (int i = COLNUM_INX; i < SCORE_INX; i++) { if (refRow[i] != null) { refRow[i] = ((String) refRow[i]).trim(); } } }
From source file:com.wso2telco.dep.reportingservice.dao.TaxDAO.java
/** * Gets the nb api request times for subscription. * * @param year the year// ww w. java 2s.co m * @param month the month * @param apiName the api name * @param apiVersion the api version * @param consumerKey the consumer key * @param operation the operation * @param category the category * @param subcategory the subcategory * @return the nb api request times for subscription * @throws Exception the exception */ public Set<APIRequestDTO> getNbAPIRequestTimesForSubscription(short year, short month, String apiName, String apiVersion, String consumerKey, int operation, String category, String subcategory) throws Exception { Connection connection = null; PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT api_version,response_count AS count,STR_TO_DATE(time,'%Y-%m-%d') as date FROM " + ReportingTable.NB_API_RESPONSE_SUMMARY + " WHERE year=? and month=? and consumerKey=? and " + "api=? and api_version=? and operationType=? and category =? and subcategory=? and responseCode like '2%'"; Set<APIRequestDTO> apiRequests = new HashSet<APIRequestDTO>(); try { connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); ps = connection.prepareStatement(sql); ps.setShort(1, year); ps.setShort(2, month); ps.setString(3, consumerKey); ps.setString(4, apiName); ps.setString(5, apiVersion); ps.setInt(6, operation); ps.setString(7, category); ps.setString(8, subcategory); results = ps.executeQuery(); while (results.next()) { APIRequestDTO req = new APIRequestDTO(); req.setApiVersion(results.getString("api_version")); req.setRequestCount(results.getInt("count")); req.setDate(results.getDate("date")); apiRequests.add(req); } } catch (SQLException e) { handleException("Error occurred while getting Request Times for Subscription", e); } finally { DbUtils.closeAllConnections(ps, connection, results); } return apiRequests; }
From source file:org.apache.hawq.pxf.plugins.jdbc.JdbcReadResolver.java
@Override public List<OneField> getFields(OneRow row) throws Exception { ResultSet result = (ResultSet) row.getData(); LinkedList<OneField> fields = new LinkedList<>(); for (int i = 0; i < columns.size(); i++) { ColumnDescriptor column = columns.get(i); String colName = column.columnName(); Object value = null;//from www . j a v a 2s . c om OneField oneField = new OneField(); oneField.type = column.columnTypeCode(); switch (DataType.get(oneField.type)) { case INTEGER: value = result.getInt(colName); break; case FLOAT8: value = result.getDouble(colName); break; case REAL: value = result.getFloat(colName); break; case BIGINT: value = result.getLong(colName); break; case SMALLINT: value = result.getShort(colName); break; case BOOLEAN: value = result.getBoolean(colName); break; case BYTEA: value = result.getBytes(colName); break; case VARCHAR: case BPCHAR: case TEXT: case NUMERIC: value = result.getString(colName); break; case TIMESTAMP: case DATE: value = result.getDate(colName); break; default: throw new UnsupportedOperationException("Unknwon Field Type : " + DataType.get(oneField.type).toString() + ", Column : " + column.toString()); } oneField.val = value; fields.add(oneField); } return fields; }
From source file:com.cws.us.pws.dao.impl.CareersReferenceDAOImpl.java
/** * @see com.cws.us.pws.dao.interfaces.ICareersReferenceDAO#getCareerData(String, String) throws SQLException *//* w w w. j a va 2 s . c o m*/ @Override public List<Object> getCareerData(final String reqId, final String lang) throws SQLException { final String methodName = ICareersReferenceDAO.CNAME + "#getCareerData(final int reqId, final String lang) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", reqId); DEBUGGER.debug("Value: {}", lang); } Connection sqlConn = null; ResultSet resultSet = null; List<Object> results = null; CallableStatement stmt = null; try { sqlConn = this.dataSource.getConnection(); if (DEBUG) { DEBUGGER.debug("Connection: {}", sqlConn); } if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain connection to application datasource"); } stmt = sqlConn.prepareCall("{ CALL getCareerData(?, ?) }"); stmt.setString(1, reqId); stmt.setString(2, lang); if (DEBUG) { DEBUGGER.debug("CallableStatement: {}", stmt); } if (!(stmt.execute())) { throw new SQLException("PreparedStatement is null. Cannot execute."); } resultSet = stmt.getResultSet(); if (DEBUG) { DEBUGGER.debug("ResultSet: {}", resultSet); } if (resultSet.next()) { resultSet.beforeFirst(); results = new ArrayList<Object>(); while (resultSet.next()) { results.add(resultSet.getString(1)); // REQ_ID results.add(resultSet.getDate(2)); // POST_DATE results.add(resultSet.getDate(3)); // UNPOST_DATE results.add(resultSet.getString(4)); // JOB_TITLE results.add(resultSet.getString(5)); // JOB_SHORT_DESC results.add(resultSet.getString(6)); // JOB_DESCRIPTION } if (DEBUG) { DEBUGGER.debug("results: {}", results); } } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); throw new SQLException(sqx.getMessage(), sqx); } finally { if (resultSet != null) { resultSet.close(); } if (stmt != null) { stmt.close(); } if ((sqlConn != null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } if (DEBUG) { DEBUGGER.debug("results: {}", results); } return results; }
From source file:com.sfs.whichdoctor.dao.ReceiptDAOImpl.java
/** * Load receipt.//from w ww.j av a 2s . c o m * * @param rs the rs * @param loadDetails the load details * * @return the receipt bean * * @throws SQLException the SQL exception */ private ReceiptBean loadReceipt(final ResultSet rs, final BuilderBean loadDetails) throws SQLException { ReceiptBean receipt = new ReceiptBean(); receipt.setId(rs.getInt("ReceiptId")); receipt.setGUID(rs.getInt("GUID")); receipt.setAbbreviation(rs.getString("Abbreviation")); receipt.setNumber(rs.getString("ReceiptNo")); receipt.setDescription(rs.getString("Description")); receipt.setProcessType(rs.getString("ProcessType")); receipt.setProcessAbbreviation(rs.getString("ProcessAbbreviation")); receipt.setBatchReference(rs.getInt("BatchReference")); receipt.setBank(rs.getString("Bank")); receipt.setBranch(rs.getString("Branch")); try { receipt.setIssued(rs.getDate("Issued")); } catch (SQLException e) { receipt.setIssued(null); } receipt.setCancelled(rs.getBoolean("Cancelled")); int organisationGUID = rs.getInt("OrganisationId"); int personGUID = rs.getInt("PersonId"); if (personGUID > 0) { receipt.setPerson(loadPerson(rs, personGUID, loadDetails)); } if (organisationGUID > 0) { receipt.setOrganisation(loadOrganisation(rs, organisationGUID, loadDetails)); } receipt.setTypeName(rs.getString("Type")); receipt.setClassName(rs.getString("ReceiptType")); receipt.setTotalValue(rs.getDouble("TotalValue")); receipt.setSecurity(rs.getString("Security")); receipt.setActive(rs.getBoolean("Active")); if (loadDetails.getBoolean("HISTORY")) { try { receipt.setCreatedDate(rs.getTimestamp("CreatedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage()); } receipt.setCreatedBy(rs.getString("CreatedBy")); try { receipt.setModifiedDate(rs.getTimestamp("ModifiedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage()); } receipt.setModifiedBy(rs.getString("ModifiedBy")); try { receipt.setExportedDate(rs.getTimestamp("ExportedDate")); } catch (SQLException sqe) { dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage()); } receipt.setExportedBy(rs.getString("ExportedBy")); } if (loadDetails.getBoolean("TAGS")) { try { receipt.setTags(this.getTagDAO().load(receipt.getGUID(), loadDetails.getString("USERDN"), true)); } catch (Exception e) { dataLogger.error("Error loading tags for receipt: " + e.getMessage()); } } if (loadDetails.getBoolean("MEMO")) { try { receipt.setMemo(this.getMemoDAO().load(receipt.getGUID(), loadDetails.getBoolean("MEMO_FULL"))); } catch (Exception e) { dataLogger.error("Error loading memos: " + e.getMessage()); } } if (loadDetails.getBoolean("PAYMENT")) { try { receipt.setPayments( this.paymentDAO.load(receipt.getGUID(), loadDetails.getBoolean("PAYMENT_FULL"))); } catch (Exception e) { dataLogger.error("Error loading payment details: " + e.getMessage()); } } if (loadDetails.getBoolean("GROUPS")) { receipt.setGroups(loadGroups(receipt.getGUID())); } if (loadDetails.getBoolean("CREATED")) { UserBean user = new UserBean(); user.setDN(rs.getString("CreatedBy")); user.setPreferredName(rs.getString("CreatedFirstName")); user.setLastName(rs.getString("CreatedLastName")); receipt.setCreatedUser(user); } if (loadDetails.getBoolean("MODIFIED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ModifiedBy")); user.setPreferredName(rs.getString("ModifiedFirstName")); user.setLastName(rs.getString("ModifiedLastName")); receipt.setModifiedUser(user); } if (loadDetails.getBoolean("EXPORTED")) { UserBean user = new UserBean(); user.setDN(rs.getString("ExportedBy")); user.setPreferredName(rs.getString("ExportedFirstName")); user.setLastName(rs.getString("ExportedLastName")); receipt.setExportedUser(user); } return receipt; }