List of usage examples for java.sql ResultSet getDouble
double getDouble(String columnLabel) throws SQLException;
ResultSet
object as a double
in the Java programming language. From source file:com.grayfox.server.dao.jdbc.RecommendationJdbcDao.java
@Override public List<Recommendation> findNearestByCategoriesLiked(String accessToken, Location location, Integer radius, Locale locale) {/* w w w .j a va 2 s.c om*/ Set<String> categoryNames = new HashSet<>(); List<Recommendation> recommendations = getJdbcTemplate() .query(getQuery("Recommendation.findNearestByCategoriesLiked", locale), (ResultSet rs, int i) -> { String categoryName = rs.getString(7); if (categoryNames.add(categoryName)) { Recommendation recommendation = new Recommendation(); Poi poi = new Poi(); int columnIndex = 1; poi.setId(rs.getLong(columnIndex++)); poi.setName(rs.getString(columnIndex++)); poi.setLocation(new Location()); poi.getLocation().setLatitude(rs.getDouble(columnIndex++)); poi.getLocation().setLongitude(rs.getDouble(columnIndex++)); poi.setFoursquareId(rs.getString(columnIndex++)); poi.setFoursquareRating(rs.getDouble(columnIndex++)); recommendation.setType(Recommendation.Type.SELF); recommendation.setReason(Messages.get("recommendation.self.reason", locale, categoryName)); recommendation.setPoi(poi); return recommendation; } else return null; }, accessToken, location.getLatitude(), location.getLongitude(), radius); recommendations = recommendations.stream().filter(Objects::nonNull).collect(Collectors.toList()); recommendations.forEach(recommendation -> recommendation.getPoi().setCategories(new HashSet<>( categoryDao.findByPoiFoursquareId(recommendation.getPoi().getFoursquareId(), locale)))); return recommendations; }
From source file:com.grayfox.server.dao.jdbc.RecommendationJdbcDao.java
@Override public List<Recommendation> findNearestByCategoriesLikedByFriends(String accessToken, Location location, Integer radius, Locale locale) { Set<String> categoryNames = new HashSet<>(); List<Recommendation> recommendations = getJdbcTemplate().query( getQuery("Recommendation.findNearestByCategoriesLikedByFriends", locale), (ResultSet rs, int i) -> { String categoryName = rs.getString(9); if (categoryNames.add(categoryName)) { Recommendation recommendation = new Recommendation(); Poi poi = new Poi(); int columnIndex = 1; poi.setId(rs.getLong(columnIndex++)); poi.setName(rs.getString(columnIndex++)); poi.setLocation(new Location()); poi.getLocation().setLatitude(rs.getDouble(columnIndex++)); poi.getLocation().setLongitude(rs.getDouble(columnIndex++)); poi.setFoursquareId(rs.getString(columnIndex++)); poi.setFoursquareRating(rs.getDouble(columnIndex++)); recommendation.setType(Recommendation.Type.SOCIAL); String friendFirstName = rs.getString(columnIndex++); String friendLastName = rs.getString(columnIndex++); String friendFullName = friendLastName == null || friendLastName.trim().isEmpty() ? friendFirstName : friendFirstName + " " + friendLastName; recommendation.setReason( Messages.get("recommendation.social.reason", locale, friendFullName, categoryName)); recommendation.setPoi(poi); return recommendation; } else return null; }, accessToken, location.getLatitude(), location.getLongitude(), radius); recommendations = recommendations.stream().filter(Objects::nonNull).collect(Collectors.toList()); recommendations.forEach(recommendation -> recommendation.getPoi().setCategories(new HashSet<>( categoryDao.findByPoiFoursquareId(recommendation.getPoi().getFoursquareId(), locale)))); return recommendations; }
From source file:com.spvp.dal.MySqlDatabase.java
@Override public Grad dajGradPoImenu(String imeGrada) throws SQLException { int id;/*from w ww. j av a 2 s . c om*/ String ime; Double longitude; Double latitude; Boolean veciCentar; try (Connection conn = getConnection()) { PreparedStatement ps = conn.prepareStatement("SELECT id, ime, longitude, latitude, veci_centar " + "FROM gradovi " + "WHERE LOWER(ime) LIKE LOWER(?) "); ps.setString(1, imeGrada); ResultSet rs = ps.executeQuery(); rs.next(); id = rs.getInt("id"); ime = rs.getString("ime"); longitude = rs.getDouble("longitude"); latitude = rs.getDouble("latitude"); veciCentar = rs.getBoolean("veci_centar"); } Grad g = new Grad(ime, longitude, latitude, veciCentar); g.setIdGrada(id); return g; }
From source file:com.sfs.whichdoctor.analysis.FinancialSummaryAnalysisDAOImpl.java
/** * Query for sub total.//from w ww . j a v a 2s.co m * * @param sqlWHERE the sql where * @param sqlDate the sql date * @param sqlType the sql type * @param parameters the parameters * * @return the double */ private double queryForSubTotal(final String sqlWHERE, final String sqlDate, final String sqlType, final Collection<Object> parameters) { double subTotal = 0; dataLogger.debug("Query subtotal: " + sqlWHERE); StringBuffer searchSQL = new StringBuffer(); searchSQL.append(this.getSQL().getValue("financialSummary/total")); searchSQL.append(sqlWHERE); searchSQL.append(sqlDate); searchSQL.append(sqlType); searchSQL.append(this.sqlORDER); dataLogger.info("SQL query: " + searchSQL.toString()); try { subTotal = (Double) this.getJdbcTemplateReader().queryForObject(searchSQL.toString(), parameters.toArray(), new RowMapper() { public Object mapRow(final ResultSet rs, final int rowNum) throws SQLException { return new Double(rs.getDouble(1)); } }); } catch (IncorrectResultSizeDataAccessException ie) { // No results found for this search dataLogger.debug("No results found for search: " + ie.getMessage()); } return subTotal; }
From source file:ngmep.osm.dao.NodeDAO.java
public Node getNode(final ResultSet resultSet) throws SQLException { final long identifier = resultSet.getLong("id"); final Node node = new Node(); node.setId(identifier);//from w w w .j a v a 2 s .c om node.setUser(UserDAO.getInstance().getUser(resultSet.getInt("user_id"))); node.setVersion(resultSet.getInt("version")); final Calendar calendario = new GregorianCalendar(); node.setTimestamp(resultSet.getTimestamp("tstamp", calendario).getTime()); node.setChangeset(resultSet.getLong("changeset_id")); node.setLat(resultSet.getDouble("lat")); node.setLon(resultSet.getDouble("lon")); try (PreparedStatement statement = Database.getConnection().prepareStatement(getQueryNodeTags());) { statement.setLong(1, identifier); try (ResultSet resultSet2 = statement.executeQuery();) { initTags(node, resultSet2); } } node.setModified(false); return node; }
From source file:com.jd.survey.dao.survey.QuestionStatisticDAOImp.java
/** * Returns descriptive statistics for numeric matrix question' answers (minimum, maximum, average, standard deviation) * @param question/*from ww w . ja v a 2 s. co m*/ * @return */ private List<QuestionStatistic> getMatrixDescriptiveStatistics(Question question, final Long totalRecordCount) { List<QuestionStatistic> questionStatistics = new ArrayList<QuestionStatistic>(); Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId(); Short pageOrder = question.getPage().getOrder(); Short questionOrder = question.getOrder(); for (QuestionRowLabel row : question.getRowLabels()) { for (QuestionColumnLabel column : question.getColumnLabels()) { final Short columnOrder = column.getOrder(); final Short rowOrder = row.getOrder(); final String columnName = "p" + pageOrder + "q" + questionOrder + "r" + rowOrder + "c" + columnOrder; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("select MIN(d." + columnName + ") as min ,MAX(d." + columnName + ") as max ,AVG(d." + columnName + ") as avg ,STDDEV_SAMP(d." + columnName + ") as std "); stringBuilder.append(" from survey_data_" + surveyDefinitionId + " d inner join survey s on (s.id=d.survey_id and s.status='S')"); String selectSQLStatement = stringBuilder.toString(); List<QuestionStatistic> questionCellStatistics = this.jdbcTemplate.query(selectSQLStatement, new RowMapper<QuestionStatistic>() { public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { QuestionStatistic questionStatistic = new QuestionStatistic(); questionStatistic.setColumnOrder(columnOrder); questionStatistic.setRowOrder(rowOrder); questionStatistic.setMin(rs.getDouble("min")); questionStatistic.setMax(rs.getDouble("max")); questionStatistic.setAverage(rs.getDouble("avg")); questionStatistic.setSampleStandardDeviation(rs.getDouble("std")); questionStatistic.setTotalCount(totalRecordCount); return questionStatistic; } }); questionStatistics.addAll(questionCellStatistics); } //loop on columns } //loop on rows return questionStatistics; }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Get the Statement column so that the results are mapped correctly. * (this has been copied from AbstractDatabaseAction and modified slightly) *//*from w ww .j a v a 2 s. c o m*/ public static Object getColumn(ResultSet set, Configuration column) throws Exception { Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type")); String dbcol = column.getAttribute("name"); Object value = null; switch (type.intValue()) { case Types.CLOB: case Types.CHAR: Clob dbClob = set.getClob(dbcol); int length = (int) dbClob.length(); InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream()); byte[] buffer = new byte[length]; asciiStream.read(buffer); String str = new String(buffer); asciiStream.close(); value = str; break; case Types.BIGINT: value = set.getBigDecimal(dbcol); break; case Types.TINYINT: value = new Byte(set.getByte(dbcol)); break; case Types.VARCHAR: value = set.getString(dbcol); break; case Types.DATE: value = set.getDate(dbcol); break; case Types.DOUBLE: value = new Double(set.getDouble(dbcol)); break; case Types.FLOAT: value = new Float(set.getFloat(dbcol)); break; case Types.INTEGER: value = new Integer(set.getInt(dbcol)); break; case Types.NUMERIC: value = new Long(set.getLong(dbcol)); break; case Types.SMALLINT: value = new Short(set.getShort(dbcol)); break; case Types.TIME: value = set.getTime(dbcol); break; case Types.TIMESTAMP: value = set.getTimestamp(dbcol); break; case Types.ARRAY: value = set.getArray(dbcol); // new Integer(set.getInt(dbcol)); break; case Types.BIT: value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol)); break; case Types.STRUCT: value = (Struct) set.getObject(dbcol); break; case Types.OTHER: value = set.getObject(dbcol); break; default: // The blob types have to be requested separately, via a Reader. value = ""; break; } return value; }
From source file:com.jd.survey.dao.survey.QuestionStatisticMSSQLDAOImp.java
/** * Returns descriptive statistics for numeric matrix question' answers (minimum, maximum, average, standard deviation) * @param question/* w w w. ja va 2 s . c o m*/ * @return */ private List<QuestionStatistic> getMatrixDescriptiveStatistics(Question question, final Long totalRecordCount) { List<QuestionStatistic> questionStatistics = new ArrayList<QuestionStatistic>(); Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId(); Short pageOrder = question.getPage().getOrder(); Short questionOrder = question.getOrder(); for (QuestionRowLabel row : question.getRowLabels()) { for (QuestionColumnLabel column : question.getColumnLabels()) { final Short columnOrder = column.getOrder(); final Short rowOrder = row.getOrder(); final String columnName = "p" + pageOrder + "q" + questionOrder + "r" + rowOrder + "c" + columnOrder; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("select MIN(d." + columnName + ") as min ,MAX(d." + columnName + ") as max ,AVG(d." + columnName + ") as avg ,STDEV(d." + columnName + ") as std "); stringBuilder.append(" from survey_data_" + surveyDefinitionId + " d inner join survey s on (s.id=d.survey_id and s.status='S')"); String selectSQLStatement = stringBuilder.toString(); List<QuestionStatistic> questionCellStatistics = this.jdbcTemplate.query(selectSQLStatement, new RowMapper<QuestionStatistic>() { public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { QuestionStatistic questionStatistic = new QuestionStatistic(); questionStatistic.setColumnOrder(columnOrder); questionStatistic.setRowOrder(rowOrder); questionStatistic.setMin(rs.getDouble("min")); questionStatistic.setMax(rs.getDouble("max")); questionStatistic.setAverage(rs.getDouble("avg")); questionStatistic.setSampleStandardDeviation(rs.getDouble("std")); questionStatistic.setTotalCount(totalRecordCount); return questionStatistic; } }); questionStatistics.addAll(questionCellStatistics); } //loop on columns } //loop on rows return questionStatistics; }
From source file:com.spvp.dal.MySqlDatabase.java
@Override public void osvjeziHistorijuPrognoza(WebService ws) throws SQLException, ParseException { try (Connection conn = getConnection()) { Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT id, ime, longitude, latitude " + "FROM gradovi"); Grad x;//from w w w . j a va 2 s . c om while (rs.next()) { x = new Grad(rs.getString("ime"), rs.getDouble("longitude"), rs.getDouble("latitude")); x.setIdGrada(rs.getInt("id")); this.osvjeziHistorijuPrognozaZaGrad(x, ws); } rs.close(); s.close(); } catch (SQLException ex) { Logger.getLogger(MySqlDatabase.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
public JSONArray getPayments(int state) { JSONArray ja = new JSONArray(); PaymentAccountDAOImp pad = new PaymentAccountDAOImp(); try {/* w ww .j a v a 2 s.co m*/ String sql = "SELECT * FROM payment_preferences WHERE state=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, state); ResultSet rs = ps.executeQuery(); int no = 0; while (rs.next()) { no++; JSONObject jo = new JSONObject(); jo.put("id", rs.getString(1)); jo.put("userid", rs.getString(2)); jo.put("reqdate", rs.getString(3)); jo.put("acctype", pad.getPaymetAccountName(rs.getInt(5))); jo.put("amount", rs.getDouble(7)); jo.put("state", rs.getInt(8)); jo.put("email", rs.getString(9)); jo.put("no", no); ja.add(jo); } return ja; } catch (Exception e) { e.printStackTrace(); } return ja; }