List of usage examples for java.sql ResultSet getFloat
float getFloat(String columnLabel) throws SQLException;
ResultSet
object as a float
in the Java programming language. From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
@Override public float getEnergyCost(EnergyMonitor energyMonitor) { float cost = -1; try {//from w ww. j av a2 s .c o m cost = jdbcTemplate.queryForObject("select cost_per_kwh from energy_costs where energy_monitor_id = ?", new Object[] { energyMonitor.getId() }, new RowMapper<Float>() { @Override public Float mapRow(ResultSet rs, int arg1) throws SQLException { return rs.getFloat("cost_per_kwh"); } }); } catch (EmptyResultDataAccessException e) { } return cost; }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStore.java
private PageStats getPageStats(String pageStatsKey) { String getPageStats = dialect.getPageStats(schema, "key"); return jt.queryForOptionalObject(getPageStats, new ParameterizedRowMapper<PageStats>() { public PageStats mapRow(ResultSet rs, int rowNum) throws SQLException { PageStats ps = new PageStats(0); // FREQUENCY_OF_USE, LAST_ACCESS_TIME, FILL_FACTOR, NUM_HITS FROM ps.setFrequencyOfUsePerMinute(rs.getFloat(1)); ps.setLastAccessMinutes(rs.getInt(2)); ps.setFillFactor(rs.getFloat(3)); ps.setNumHits(rs.getBigDecimal(4).toBigInteger()); return ps; }/*from ww w. j a v a 2 s. c o m*/ }, Collections.singletonMap("key", pageStatsKey)); }
From source file:org.mskcc.cbio.portal.dao.DaoMutation.java
private static ExtendedMutation.MutationEvent extractMutationEvent(ResultSet rs) throws SQLException, DaoException { ExtendedMutation.MutationEvent event = new ExtendedMutation.MutationEvent(); event.setMutationEventId(rs.getLong("MUTATION_EVENT_ID")); long entrezId = rs.getLong("mutation_event.ENTREZ_GENE_ID"); DaoGeneOptimized aDaoGene = DaoGeneOptimized.getInstance(); CanonicalGene gene = aDaoGene.getGene(entrezId); event.setGene(gene);//w ww. j av a 2 s . com event.setChr(rs.getString("CHR")); event.setStartPosition(rs.getLong("START_POSITION")); event.setEndPosition(rs.getLong("END_POSITION")); event.setProteinChange(rs.getString("PROTEIN_CHANGE")); event.setMutationType(rs.getString("MUTATION_TYPE")); event.setFunctionalImpactScore(rs.getString("FUNCTIONAL_IMPACT_SCORE")); event.setFisValue(rs.getFloat("FIS_VALUE")); event.setLinkXVar(rs.getString("LINK_XVAR")); event.setLinkPdb(rs.getString("LINK_PDB")); event.setLinkMsa(rs.getString("LINK_MSA")); event.setNcbiBuild(rs.getString("NCBI_BUILD")); event.setStrand(rs.getString("STRAND")); event.setVariantType(rs.getString("VARIANT_TYPE")); event.setDbSnpRs(rs.getString("DB_SNP_RS")); event.setDbSnpValStatus(rs.getString("DB_SNP_VAL_STATUS")); event.setReferenceAllele(rs.getString("REFERENCE_ALLELE")); event.setOncotatorDbSnpRs(rs.getString("ONCOTATOR_DBSNP_RS")); event.setOncotatorRefseqMrnaId(rs.getString("ONCOTATOR_REFSEQ_MRNA_ID")); event.setOncotatorCodonChange(rs.getString("ONCOTATOR_CODON_CHANGE")); event.setOncotatorUniprotName(rs.getString("ONCOTATOR_UNIPROT_ENTRY_NAME")); event.setOncotatorUniprotAccession(rs.getString("ONCOTATOR_UNIPROT_ACCESSION")); event.setOncotatorProteinPosStart(rs.getInt("ONCOTATOR_PROTEIN_POS_START")); event.setOncotatorProteinPosEnd(rs.getInt("ONCOTATOR_PROTEIN_POS_END")); event.setCanonicalTranscript(rs.getBoolean("CANONICAL_TRANSCRIPT")); event.setTumorSeqAllele(rs.getString("TUMOR_SEQ_ALLELE")); event.setKeyword(rs.getString("KEYWORD")); return event; }
From source file:org.hyperic.hq.plugin.sybase.SybaseMeasurementPlugin.java
private float getNumReuse(Connection conn, String configOpt) throws SQLException { Statement stmt = null;/*w w w . j a v a2s .c o m*/ ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("sp_monitorconfig '" + configOpt + "'"); ResultSetMetaData rsmd = rs.getMetaData(); // I have seen Num_Reuse, Reuse and Reuse_cnt so far for this String reuseCol = "Num_Reuse"; for (int i = 1; i <= rsmd.getColumnCount(); i++) { String name = rsmd.getColumnName(i); if (name.indexOf("Reuse") != -1) { reuseCol = name; } } int col = rs.findColumn(reuseCol); if (rs.next()) { return rs.getFloat(col); } } finally { DBUtil.closeJDBCObjects(log, null, stmt, rs); } throw new SQLException(); }
From source file:org.apache.phoenix.end2end.CursorWithRowValueConstructorIT.java
@Test public void testCursorsWithColsOfTypesTinyintSmallintFloatDouble() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts - 1, getUrl(), null); ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts - 1); String query = "SELECT a_byte,a_short,a_float,a_double FROM aTable WHERE ?=organization_id AND entity_id IN (?,?,?)"; query = query.replaceFirst("\\?", "'" + tenantId + "'"); query = query.replaceFirst("\\?", "'" + ROW1 + "'"); query = query.replaceFirst("\\?", "'" + ROW2 + "'"); query = query.replaceFirst("\\?", "'" + ROW3 + "'"); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try {//from ww w. j a v a 2 s . c o m String cursor = "DECLARE testCursor CURSOR FOR " + query; conn.prepareStatement(cursor).execute(); cursor = "OPEN testCursor"; conn.prepareStatement(cursor).execute(); cursor = "FETCH NEXT FROM testCursor"; ResultSet rs = conn.prepareStatement(cursor).executeQuery(); int count = 0; while (rs.next()) { assertTrue( (byte) 1 == (rs.getByte(1)) || (byte) 2 == (rs.getByte(1)) || (byte) 3 == (rs.getByte(1))); assertTrue((short) 128 == (rs.getShort(2)) || (short) 129 == (rs.getShort(2)) || (short) 130 == (rs.getShort(2))); assertTrue(0.01f == (rs.getFloat(3)) || 0.02f == (rs.getFloat(3)) || 0.03f == (rs.getFloat(3))); assertTrue( 0.0001 == (rs.getDouble(4)) || 0.0002 == (rs.getDouble(4)) || 0.0003 == (rs.getDouble(4))); count++; if (count == 3) break; rs = conn.prepareStatement(cursor).executeQuery(); } assertTrue(count == 3); } finally { String sql = "CLOSE testCursor"; conn.prepareStatement(sql).execute(); conn.close(); } }
From source file:com.nabla.wapp.server.json.SqlColumn.java
public void write(final ResultSet rs, int column, final JSONObject record) throws SQLException { switch (type) { case Types.BIGINT: case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT: record.put(label, rs.getInt(column)); break;/*w ww . ja v a 2s . c o m*/ case Types.BOOLEAN: case Types.BIT: record.put(label, rs.getBoolean(column)); break; case Types.DATE: final Date dt = rs.getDate(column); if (rs.wasNull()) record.put(label, null); else record.put(label, new JSonDate(dt)); return; case Types.TIMESTAMP: final Timestamp tm = rs.getTimestamp(column); if (rs.wasNull()) record.put(label, null); else record.put(label, timeStampFormat.format(tm)); return; case Types.DOUBLE: record.put(label, rs.getDouble(column)); break; case Types.FLOAT: record.put(label, rs.getFloat(column)); break; case Types.NULL: record.put(label, null); return; default: record.put(label, rs.getString(column)); break; } if (rs.wasNull()) record.put(label, null); }
From source file:om.edu.squ.squportal.portlet.dps.registration.dropw.db.DropWDBImpl.java
/** * /*from w ww . j av a 2s.com*/ * method name : getCourseList * @param student * @param locale * @return * DropWDBImpl * return type : List<DropWDTO> * * purpose : Get list of courses for drop * * Date : Mar 30, 2017 8:20:37 AM */ public List<DropWDTO> getCourseList(Student student, Locale locale, String studentMode, String isWithdrawPeriodRule) { String SQL_DROPW_SELECT_COURSE_DETAILS = queryDropWProps .getProperty(Constants.CONST_SQL_DROPW_SELECT_COURSE_DETAILS); RowMapper<DropWDTO> rowMapper = new RowMapper<DropWDTO>() { @Override public DropWDTO mapRow(ResultSet rs, int rowNum) throws SQLException { DropWDTO dropWDTO = new DropWDTO(); dropWDTO.setlAbrCourseNo(rs.getString(Constants.CONST_COLMN_L_ABR_CRSNO)); dropWDTO.setCourseNo(rs.getString(Constants.CONST_COLMN_COURSE_NO)); dropWDTO.setCourseName(rs.getString(Constants.CONST_COLMN_COURSE_NAME)); dropWDTO.setSectCode(rs.getString(Constants.CONST_COLMN_SECT_CODE)); dropWDTO.setSectionNo(rs.getString(Constants.CONST_COLMN_SECTION_NO)); dropWDTO.setYearSemester(rs.getString(Constants.CONST_COLMN_YEAR_SEM)); dropWDTO.setCredits(rs.getInt(Constants.CONST_COLMN_CREDITS)); dropWDTO.setTutionFees(rs.getFloat(Constants.CONST_COLMN_TUTION_FEE)); dropWDTO.setStatusDesc(rs.getString(Constants.CONST_COLMN_STATUS_DESC)); return dropWDTO; } }; Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("paramStdId", student.getAcademicDetail().getId()); paramMap.put("paramLocale", locale.getLanguage()); paramMap.put("paramMode", studentMode); paramMap.put("paramDropTimeApplied", isWithdrawPeriodRule); return nPJdbcTemplDpsDropW.query(SQL_DROPW_SELECT_COURSE_DETAILS, paramMap, rowMapper); }
From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java
protected void convertTuple(ResultSet resultSet, VTuple tuple) { try {// w ww.j ava 2s. c o m for (int column_idx = 0; column_idx < targets.length; column_idx++) { final Column c = targets[column_idx]; final int resultIdx = column_idx + 1; switch (c.getDataType().getType()) { case INT1: case INT2: tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx))); break; case INT4: tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx))); break; case INT8: tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx))); break; case FLOAT4: tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx))); break; case FLOAT8: tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx))); break; case CHAR: tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx))); break; case VARCHAR: case TEXT: // TODO - trim is unnecessary in many cases, so we can use it for certain cases tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim())); break; case DATE: final Date date = resultSet.getDate(resultIdx); tuple.put(column_idx, DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate())); break; case TIME: final Time time = resultSet.getTime(resultIdx); tuple.put(column_idx, new TimeDatum( DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0))); break; case TIMESTAMP: tuple.put(column_idx, DatumFactory .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime())); break; case BINARY: case VARBINARY: case BLOB: tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx))); break; default: throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name())); } } } catch (SQLException s) { throw new TajoInternalError(s); } }
From source file:playground.sergioo.workplaceCapacities2012.MainWorkplaceCapacities.java
private static ActivityFacilitiesImpl capacitiesToBuildings() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoConnectionException { ActivityFacilitiesImpl facilities = (ActivityFacilitiesImpl) FacilitiesUtils.createActivityFacilities(); DataBaseAdmin dataBaseAux = new DataBaseAdmin(new File("./data/facilities/DataBaseAuxiliar.properties")); ResultSet buildingsR = dataBaseAux.executeQuery( "SELECT objectid, mpb.x as xcoord, mpb.y as ycoord, perc_surf as area_perc, fea_id AS id_building, postal_code as postal_code FROM work_facilities_aux.masterplan_areas mpa LEFT JOIN work_facilities_aux.masterplan_building_perc mpb ON mpa.objectid = mpb.object_id WHERE use_for_generation = 1"); int b = 0;//from w ww .j a va 2 s .c o m Collection<Link> noCarLinks = new ArrayList<Link>(); for (Link link : network.getLinks().values()) if (!link.getAllowedModes().contains("car")) noCarLinks.add(link); for (Link link : noCarLinks) network.removeLink(link.getId()); Map<String, Double> scheduleCapacities = new HashMap<String, Double>(); while (buildingsR.next()) { Id<ActivityFacility> areaId = Id.create(buildingsR.getString(1), ActivityFacility.class); MPAreaData mPArea = dataMPAreas.get(areaId); Id<ActivityFacility> id = Id.create((int) (buildingsR.getFloat(5)), ActivityFacility.class); if (facilities.getFacilities().get(id) != null) continue; ActivityFacilityImpl building = facilities.createAndAddFacility(id, new CoordImpl(buildingsR.getDouble(2), buildingsR.getDouble(3))); building.setLinkId(((NetworkImpl) network).getNearestLinkExactly(building.getCoord()).getId()); building.setDesc(buildingsR.getString(6) + ":" + mPArea.getType().replaceAll("&", "AND")); double proportion = buildingsR.getDouble(4); for (ActivityOption activityOptionArea : mPArea.getActivityOptions().values()) { double capacity = activityOptionArea.getCapacity() * proportion; if (capacity > 0) { Double scheduleCapacity = scheduleCapacities.get(activityOptionArea.getType()); if (scheduleCapacity == null) scheduleCapacity = 0.0; scheduleCapacities.put(activityOptionArea.getType(), scheduleCapacity + capacity); ActivityOptionImpl activityOption = new ActivityOptionImpl(activityOptionArea.getType()); activityOption.setFacility(building); activityOption.setCapacity(capacity); activityOption.addOpeningTime(activityOptionArea.getOpeningTimes().first()); building.getActivityOptions().put(activityOption.getType(), activityOption); } } b++; } System.out.println(b + " buildings"); int numDesiredSchedules = 10; String[] schedules = new String[numDesiredSchedules]; for (int n = 0; n < schedules.length; n++) { double maxCap = 0; String maxSchedule = ""; for (Entry<String, Double> cap : scheduleCapacities.entrySet()) { boolean in = false; for (int c = 0; c < n; c++) if (schedules[c].equals(cap.getKey())) in = true; if (!in && cap.getValue() > maxCap) { maxCap = cap.getValue(); maxSchedule = cap.getKey(); } } schedules[n] = maxSchedule; } //capacitiesToIntegers(facilities); for (Link link : noCarLinks) network.addLink(link); WorkersBSPainter painter = new WorkersBSPainter(network); painter.setData(facilities, schedules); new BSSimpleNetworkWindow("Building capacities", painter).setVisible(true); return facilities; }
From source file:org.etudes.component.app.jforum.JForumBaseDateServiceImpl.java
/** * @see org.etudes.api.app.jforum.JForumBaseDateService#applyBaseDateTx(String, int) *//* w w w . j a va2 s . c om*/ public void applyBaseDateTx(String course_id, int days_diff) { if (course_id == null) { throw new IllegalArgumentException("applyBaseDateTx: course_id is null"); } if (days_diff == 0) { return; } // forum dates StringBuilder sql = new StringBuilder(); sql.append("UPDATE JFORUM_FORUMS JF, JFORUM_SAKAI_COURSE_CATEGORIES JSCC SET"); sql.append( " JF.START_DATE=DATE_ADD(JF.START_DATE,INTERVAL ? DAY), JF.END_DATE=DATE_ADD(JF.END_DATE,INTERVAL ? DAY), JF.ALLOW_UNTIL_DATE=DATE_ADD(JF.ALLOW_UNTIL_DATE,INTERVAL ? DAY)"); sql.append(" WHERE JF.CATEGORIES_ID=JSCC.CATEGORIES_ID AND JSCC.COURSE_ID =?"); Object[] fields = new Object[4]; int i = 0; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = course_id; if (!sqlService.dbWrite(sql.toString(), fields)) { throw new RuntimeException("applyBaseDate: db write failed"); } // category dates sql = new StringBuilder(); sql.append("UPDATE JFORUM_CATEGORIES JC, JFORUM_SAKAI_COURSE_CATEGORIES JSCC SET"); sql.append( " JC.START_DATE=DATE_ADD(JC.START_DATE,INTERVAL ? DAY), JC.END_DATE=DATE_ADD(JC.END_DATE,INTERVAL ? DAY), JC.ALLOW_UNTIL_DATE=DATE_ADD(JC.ALLOW_UNTIL_DATE,INTERVAL ? DAY)"); sql.append(" WHERE JC.CATEGORIES_ID=JSCC.CATEGORIES_ID AND JSCC.COURSE_ID =?"); fields = new Object[4]; i = 0; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = course_id; if (!sqlService.dbWrite(sql.toString(), fields)) { throw new RuntimeException("applyBaseDate: db write failed"); } // topic dates sql = new StringBuilder(); sql.append("UPDATE JFORUM_SAKAI_COURSE_CATEGORIES JSCC, JFORUM_FORUMS JF, JFORUM_TOPICS JT SET"); sql.append( " JT.START_DATE=DATE_ADD(JT.START_DATE,INTERVAL ? DAY), JT.END_DATE=DATE_ADD(JT.END_DATE,INTERVAL ? DAY), JT.ALLOW_UNTIL_DATE=DATE_ADD(JT.ALLOW_UNTIL_DATE,INTERVAL ? DAY)"); sql.append( " WHERE JSCC.COURSE_ID =? AND JF.CATEGORIES_ID=JSCC.CATEGORIES_ID AND JT.FORUM_ID = JF.FORUM_ID"); fields = new Object[4]; i = 0; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = days_diff; fields[i++] = course_id; if (!sqlService.dbWrite(sql.toString(), fields)) { throw new RuntimeException("applyBaseDate: db write failed"); } // get grades added to gradebook sql = new StringBuilder(); sql.append( "SELECT grade_id, context, grade_type, forum_id, topic_id, points, add_to_gradebook, categories_id "); sql.append(" FROM jforum_grade j WHERE context = ? AND add_to_gradebook = 1"); fields = new Object[1]; i = 0; fields[i++] = course_id; final List<Grade> siteGrades = new ArrayList<Grade>(); this.sqlService.dbRead(sql.toString(), fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { Grade grade = new GradeImpl(); ((GradeImpl) grade).setId(result.getInt("grade_id")); grade.setContext(result.getString("context")); grade.setType(result.getInt("grade_type")); grade.setForumId(result.getInt("forum_id")); grade.setTopicId(result.getInt("topic_id")); grade.setPoints(result.getFloat("points")); grade.setAddToGradeBook(result.getInt("add_to_gradebook") == 1); grade.setCategoryId(result.getInt("categories_id")); siteGrades.add(grade); return null; } catch (SQLException e) { if (logger.isWarnEnabled()) { logger.warn("read site grades: " + e, e); } return null; } } }); // grading is only at one level either category or forum or topic and same goes with dates for (Grade siteGrade : siteGrades) { if (siteGrade.getType() == Grade.GradeType.CATEGORY.getType()) { updateGradebookCategory(siteGrade); } else if (siteGrade.getType() == Grade.GradeType.FORUM.getType()) { updateGradebookForum(siteGrade); } else if (siteGrade.getType() == Grade.GradeType.TOPIC.getType()) { updateGradebookTopic(siteGrade); } } }