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.jd.survey.dao.survey.QuestionStatisticMSSQLDAOImp.java
/** * Returns descriptive statistics for numeric question' answers (minimum, maximum, average, standard deviation) * @param question//from ww w . j a v a 2 s . c om * @return */ private List<QuestionStatistic> getDescriptiveStatistics(Question question, final Long totalRecordCount) { Long surveyDefinitionId = question.getPage().getSurveyDefinition().getId(); Short pageOrder = question.getPage().getOrder(); Short questionOrder = question.getOrder(); final String columnName = "p" + pageOrder + "q" + questionOrder; 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> questionStatistics = this.jdbcTemplate.query(selectSQLStatement, new RowMapper<QuestionStatistic>() { public QuestionStatistic mapRow(ResultSet rs, int rowNum) throws SQLException { QuestionStatistic questionStatistic = new QuestionStatistic(); 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; } }); return questionStatistics; }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public Doubletop getDoubletop(String id) { //return requested double pattern LOG.info("Returning requested double top pattern", id); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from doubletop where id=" + id; List<Doubletop> doubletop = jdbcTemplate.query(sql, new RowMapper<Doubletop>() { @Override//from w w w .j a v a 2s . c om public Doubletop mapRow(ResultSet rs, int rowNumber) throws SQLException { Doubletop doubletop1 = new Doubletop(); doubletop1.setBreakPointPrice(rs.getDouble("breakPointPrice")); doubletop1.setFirstMaxPrice(rs.getDouble("firstMaxPrice")); doubletop1.setFirstMinPrice(rs.getDouble("firstMinPrice")); doubletop1.setSecondMaxPrice(rs.getDouble("secondMaxPrice")); doubletop1.setBreakPoint(rs.getString("breakPoint")); doubletop1.setFirstMax(rs.getString("firstMax")); doubletop1.setFirstMin(rs.getString("firstMin")); doubletop1.setSecondMax(rs.getString("secondMax")); return doubletop1; } }); return doubletop.get(0); }
From source file:com.imagelake.control.PaymentPreferenceDAOImp.java
@Override public PaymentPreferences getPendingEarning(int uid, int state) { PaymentPreferences pp = null;/* w w w .j a v a2s . c o m*/ try { String sql = "SELECT * FROM payment_preferences WHERE user_id=? AND state=?"; PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ps.setInt(1, uid); ps.setInt(2, state); ResultSet rs = ps.executeQuery(); while (rs.next()) { pp = new PaymentPreferences(); pp.setAcc_type(rs.getInt(5)); pp.setAdm_id(rs.getInt(6)); pp.setAmount(rs.getDouble(7)); pp.setConf_date(rs.getString(4)); pp.setDate(rs.getString(3)); pp.setPpid(rs.getInt(1)); pp.setState(rs.getInt(8)); pp.setUser_id(rs.getInt(2)); System.out.println("getting..."); } } catch (Exception e) { e.printStackTrace(); } return pp; }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public TrippleTop getTrippleTop(String id) { //return requested triple top pattern LOG.info("Returning requested triple top pattern", id); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from trippletop where id=" + id; List<TrippleTop> trippletop = jdbcTemplate.query(sql, new RowMapper<TrippleTop>() { @Override//from w w w. j a v a 2 s. co m public TrippleTop mapRow(ResultSet rs, int rowNumber) throws SQLException { TrippleTop trippletop1 = new TrippleTop(); trippletop1.setBreakPointPrice(rs.getDouble("breakPointPrice")); trippletop1.setFirstMaxPrice(rs.getDouble("firstMaxPrice")); trippletop1.setSecondMaxPrice(rs.getDouble("secondMaxPrice")); trippletop1.setThirdMaxPrice(rs.getDouble("thirdMaxPrice")); trippletop1.setFirstMinPrice(rs.getDouble("firstMinPrice")); trippletop1.setSecondMinPrice(rs.getDouble("secondMinPrice")); trippletop1.setBreakPoint(rs.getString("breakPoint")); trippletop1.setFirstMax(rs.getString("firstMax")); trippletop1.setSecondMax(rs.getString("secondMax")); trippletop1.setThirdMax(rs.getString("thirdMax")); trippletop1.setFirstMin(rs.getString("firstMin")); trippletop1.setSecondMin(rs.getString("secondMin")); return trippletop1; } }); return trippletop.get(0); }
From source file:nl.tudelft.stocktrader.derby.DerbyMarketSummaryDAO.java
public List<Quote> getAllQuotes() throws DAOException { if (logger.isDebugEnabled()) { logger.debug("MarketSummaryDAO.getAllQuotes()"); }// w ww . j av a2 s.c o m PreparedStatement selectQuote = null; try { selectQuote = sqlConnection.prepareStatement(SQL_SELECT_ALL_QUOTES); ResultSet rs = selectQuote.executeQuery(); try { ArrayList<Quote> quotes = new ArrayList<Quote>(); while (rs.next()) { Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4), rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8)); quotes.add(quote); } return quotes; } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } } catch (SQLException e) { throw new DAOException("", e); } finally { try { if (selectQuote != null) { selectQuote.close(); } } catch (SQLException e) { logger.debug("", e); } } }
From source file:org.apache.ctakes.ytex.kernel.SparseDataExporterImpl.java
/** * /* w w w . ja v a 2 s . c o m*/ * @param sql * result 1st column: instance id, 2nd column: word, 3rd column: * numeric word value * @param instanceNumericWords * map of instance id - [map word - word value] to be populated */ protected void getNumericInstanceWords(final String sql, final String prepareScript, final String prepareScriptDelimiter, final SparseData sparseData, final Map<String, Object> params) { txTemplateNew.execute(new TransactionCallback<Object>() { @Override public Object doInTransaction(TransactionStatus txStatus) { prepare(prepareScript, prepareScriptDelimiter, params); namedJdbcTemplate.query(sql, params // new PreparedStatementCreator() { // // @Override // public PreparedStatement createPreparedStatement( // Connection conn) throws SQLException { // return conn.prepareStatement(sql, // ResultSet.TYPE_FORWARD_ONLY, // ResultSet.CONCUR_READ_ONLY); // } // // } , new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { long instanceId = rs.getLong(1); String word = rs.getString(2); double wordValue = rs.getDouble(3); addNumericWordToInstance(sparseData, instanceId, word, wordValue); } }); return null; } }); }
From source file:com.dbsvg.models.SQLiteInternalDataDAO.java
public void makeViewWCoordinates(Table t, SchemaPage page, int numTables, Connection conn, boolean makeViewsForAllTables) throws SQLException { PreparedStatement ps = conn.prepareStatement(SELECT_TV_SQL); ps.setString(1, page.getId().toString()); ps.setString(2, t.getId().toString()); ResultSet rs = ps.executeQuery(); if (rs.next()) { TableView tv = page.makeViewForTable(t); tv.setX(rs.getDouble("x_pos")); tv.setY(rs.getDouble("y_pos")); LOG.debug("Populated Coordinates for: " + tv.getTable().getName() + "{" + tv.getX() + "," + tv.getY() + "}"); tv.calcLinksAndRadius();/*from ww w .j a va 2 s. c o m*/ tv.setSorted(); LOG.info("Read TableView from db {}", tv); } else if (makeViewsForAllTables) { TableView tv = page.makeViewForTable(t); tv.randomInitialize(numTables); LOG.info("No TableView found for table. Created blank view for this page {}", tv); } rs.close(); }
From source file:de.tudarmstadt.lt.nlkg.DT.java
public Entry get(String word, int max_dt_words) { try {//from w ww. j a va 2 s .c o m String query = String.format( "SELECT word2,count FROM `dt` WHERE word1 LIKE '%s' ORDER BY count DESC LIMIT %d;", word, max_dt_words + 1); final Connection c = connect(); final Statement s = c.createStatement(); final ResultSet r = s.executeQuery(query); if (!r.next()) return Entry.EMPTY; Entry result = new Entry() { { word = new Word() { { word = r.getString(1); significance = r.getDouble(2); } }; dtwords = new Iterator<Word>() { @Override public boolean hasNext() { try { if (r.isClosed()) return false; if (r.next()) return true; r.close(); s.close(); return false; } catch (SQLException e) { e.printStackTrace(); return false; } } @Override public Word next() { try { return new Word() { { word = r.getString(1); significance = r.getDouble(2); } }; } catch (SQLException e) { e.printStackTrace(); return Word.EMPTY; } } @Override public void remove() { throw new UnsupportedOperationException(); } @Override protected void finalize() throws Throwable { r.close(); r.close(); super.finalize(); } }; } }; return result; } catch (Exception e) { e.printStackTrace(); return Entry.EMPTY; } }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public DoubleBottom getDoubleBottom(String id) { //return requested double bottom pattern LOG.info("Returning requested double bottom pattern", id); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from doublebottom where id=" + id; List<DoubleBottom> doublebottom = jdbcTemplate.query(sql, new RowMapper<DoubleBottom>() { @Override// w w w . j a va 2s . c o m public DoubleBottom mapRow(ResultSet rs, int rowNumber) throws SQLException { DoubleBottom doublebottom1 = new DoubleBottom(); doublebottom1.setBreakPointPrice(rs.getDouble("breakPointPrice")); doublebottom1.setFirstMaxPrice(rs.getDouble("firstMaxPrice")); doublebottom1.setFirstMinPrice(rs.getDouble("firstMinPrice")); doublebottom1.setSecondMinPrice(rs.getDouble("secondMinPrice")); doublebottom1.setBreakPoint(rs.getString("breakPoint")); doublebottom1.setFirstMax(rs.getString("firstMax")); doublebottom1.setFirstMin(rs.getString("firstMin")); doublebottom1.setSecondMin(rs.getString("secondMin")); return doublebottom1; } }); return doublebottom.get(0); }
From source file:com.arcane.dao.Impl.PatternDaoImpl.java
@Override public TrippleBottom getTrippleBottom(String id) { //return requested triple bottom pattern LOG.info("Selecting requested pattern ", id); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String sql = "SELECT * from tripplebottom where id=" + id; List<TrippleBottom> trippleBottom = jdbcTemplate.query(sql, new RowMapper<TrippleBottom>() { @Override/*from www.j a v a 2 s.c o m*/ public TrippleBottom mapRow(ResultSet rs, int rowNumber) throws SQLException { TrippleBottom trippleBottom1 = new TrippleBottom(); trippleBottom1.setFirstMinPrice(rs.getDouble("firstMinPrice")); trippleBottom1.setSecondMinPrice(rs.getDouble("secondMinPrice")); trippleBottom1.setThirdMinPrice(rs.getDouble("thirdMinPrice")); trippleBottom1.setBreakPointPrice(rs.getDouble("breakPointPrice")); trippleBottom1.setFirstMaxPrice(rs.getDouble("firstMaxPrice")); trippleBottom1.setSecondMaxPrice(rs.getDouble("secondMaxPrice")); trippleBottom1.setFirstMin(rs.getString("firstMin")); trippleBottom1.setSecondMin(rs.getString("secondMin")); trippleBottom1.setThirdMin(rs.getString("thirdMin")); trippleBottom1.setBreakPoint(rs.getString("breakPoint")); trippleBottom1.setFirstMax(rs.getString("firstMax")); trippleBottom1.setSecondMax(rs.getString("secondMax")); return trippleBottom1; } }); return trippleBottom.get(0); }