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:org.openconcerto.erp.core.finance.tax.model.TaxeCache.java
private TaxeCache() { final DBRoot root = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete(); final SQLTable table = root.getTable("TAXE"); final SQLSelect sel = new SQLSelect(table.getBase()); sel.addSelect(table.getField("ID_TAXE")); sel.addSelect(table.getField("TAUX")); final String req = sel.asString(); root.getDBSystemRoot().getDataSource().execute(req, new ResultSetHandler() { public Object handle(final ResultSet resultSet) throws SQLException { while (resultSet.next()) { final int idTaxe = resultSet.getInt(1); final Float resultTaux = Float.valueOf(resultSet.getFloat(2)); TaxeCache.this.mapTaux.put(Integer.valueOf(idTaxe), resultTaux); }//from w w w . j a v a2 s . c o m return null; } }); }
From source file:com.javacodegags.waterflooding.model.ParametersImplemented.java
@Override public List<Parameters> getListById(int parameterId) { String sql = "SELECT * " + "FROM parameters " + "INNER JOIN criteria " + "ON parameters.foreign_to_criteria=criteria.Id " + "Where parameters.foreign_to_criteria=" + parameterId + ";"; List<Parameters> listParameters = jdbcTemplate.query(sql, new RowMapper<Parameters>() { @Override/*from ww w. j a v a 2s. c o m*/ public Parameters mapRow(ResultSet rs, int rowNum) throws SQLException { Parameters parameters = new Parameters(); parameters.setId(rs.getInt("id")); parameters.setName(rs.getString("name")); parameters.setValue(rs.getFloat("value")); parameters.setForeignId(rs.getInt("foreign_to_criteria")); return parameters; } }); return listParameters; }
From source file:OutputApplet.java
/** * The "run" method is called from the worker thread. Notice that because * this method is doing potentially slow databases accesses we avoid making * it a synchronized method./*from w w w. ja v a2 s. c o m*/ */ public void run() { String url = "jdbc:mySubprotocol:myDataSource"; String query = "select COF_NAME, PRICE from COFFEES"; try { Class.forName("myDriver.ClassName"); } catch (Exception ex) { setError("Can't find Database driver class: " + ex); return; } try { Vector results = new Vector(); Connection con = DriverManager.getConnection(url, "myLogin", "myPassword"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String s = rs.getString("COF_NAME"); float f = rs.getFloat("PRICE"); String text = s + " " + f; results.addElement(text); } stmt.close(); con.close(); setResults(results); } catch (SQLException ex) { setError("SQLException: " + ex); } }
From source file:org.castor.jdo.engine.SQLTypeInfos.java
/** * Get value from given ResultSet at given index with given SQL type. * /* ww w.j a v a 2s . c o m*/ * @param rs The ResultSet to get the value from. * @param index The index of the value in the ResultSet. * @param sqlType The SQL type of the value. * @return The value. * @throws SQLException If a database access error occurs. */ public static Object getValue(final ResultSet rs, final int index, final int sqlType) throws SQLException { switch (sqlType) { case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: return rs.getString(index); case Types.DECIMAL: case Types.NUMERIC: return rs.getBigDecimal(index); case Types.INTEGER: int intVal = rs.getInt(index); return (rs.wasNull() ? null : new Integer(intVal)); case Types.TIME: return rs.getTime(index, getCalendar()); case Types.DATE: return rs.getDate(index); case Types.TIMESTAMP: return rs.getTimestamp(index, getCalendar()); case Types.FLOAT: case Types.DOUBLE: double doubleVal = rs.getDouble(index); return (rs.wasNull() ? null : new Double(doubleVal)); case Types.REAL: float floatVal = rs.getFloat(index); return (rs.wasNull() ? null : new Float(floatVal)); case Types.SMALLINT: short shortVal = rs.getShort(index); return (rs.wasNull() ? null : new Short(shortVal)); case Types.TINYINT: byte byteVal = rs.getByte(index); return (rs.wasNull() ? null : new Byte(byteVal)); case Types.LONGVARBINARY: case Types.VARBINARY: case Types.BINARY: return rs.getBytes(index); case Types.BLOB: Blob blob = rs.getBlob(index); return (blob == null ? null : blob.getBinaryStream()); case Types.CLOB: return rs.getClob(index); case Types.BIGINT: long longVal = rs.getLong(index); return (rs.wasNull() ? null : new Long(longVal)); case Types.BIT: boolean boolVal = rs.getBoolean(index); return (rs.wasNull() ? null : new Boolean(boolVal)); default: Object value = rs.getObject(index); return (rs.wasNull() ? null : value); } }
From source file:OutputApplet.java
/** * The "run" method is called from the worker thread. Notice that * because this method is doing potentially slow databases accesses * we avoid making it a synchronized method. */// w ww . j ava2s . co m public void run() { String url = "jdbc:mySubprotocol:myDataSource"; String query = "select COF_NAME, PRICE from COFFEES"; try { Class.forName("myDriver.ClassName"); } catch (Exception ex) { setError("Can't find Database driver class: " + ex); return; } try { Vector results = new Vector(); Connection con = DriverManager.getConnection(url, "myLogin", "myPassword"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String s = rs.getString("COF_NAME"); float f = rs.getFloat("PRICE"); String text = s + " " + f; results.addElement(text); } stmt.close(); con.close(); setResults(results); } catch (SQLException ex) { setError("SQLException: " + ex); } }
From source file:com.butler.service.ProductDao.java
public List<Product> getAllProducts() { String sql = "select name,display_name,market_price,selling_price,size,type,booking_only from product where visible=1 order by display_position,booking_only"; return this.getJdbcTemplate().query(sql, new RowMapper() { @Override//from w w w. j av a 2 s .c o m public Object mapRow(ResultSet rs, int i) throws SQLException { Product product = new Product(); product.setName(rs.getString("name")); product.setDisplayName(rs.getString("display_name")); product.setSellingPrice(rs.getFloat("selling_price")); product.setMarketPrice(rs.getFloat("market_price")); product.setSizeSpecification(rs.getString("size")); product.setType(rs.getString("type")); product.setBookingOnly(rs.getBoolean("booking_only")); return product; } }); }
From source file:com.butler.service.ProductDao.java
public List<Product> getCompeteProducts() { String sql = "select name,display_name,display_position,market_price,selling_price,size,type,visible,booking_only from product order by display_position"; return this.getJdbcTemplate().query(sql, new RowMapper() { @Override/*from w w w . j a v a 2s .c om*/ public Object mapRow(ResultSet rs, int i) throws SQLException { Product product = new Product(); product.setName(rs.getString("name")); product.setDisplayName(rs.getString("display_name")); product.setSellingPrice(rs.getFloat("selling_price")); product.setMarketPrice(rs.getFloat("market_price")); product.setSizeSpecification(rs.getString("size")); product.setType(rs.getString("type")); product.setVisible(rs.getBoolean("visible")); product.setDisplayPosition(rs.getInt("display_position")); product.setBookingOnly(rs.getBoolean("booking_only")); return product; } }); }
From source file:com.mobilewallet.users.dao.BalanceDAO.java
public Balance balanceInfo(long userId) { Balance w = null;/*from w ww. j av a 2 s . c o m*/ Connection con = null; PreparedStatement pstmt = null; ResultSet rs = null; try { con = dataSource.getConnection(); pstmt = con.prepareStatement(walletInfoQuery); pstmt.setLong(1, userId); rs = pstmt.executeQuery(); if (rs.next()) { w = new Balance(); w.setAmount(rs.getFloat("w_amount")); w.setTotalAmount(rs.getFloat("w_total_credits")); } } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (rs != null) { rs.close(); } } catch (Exception ex) { } try { if (pstmt != null) { pstmt.close(); } } catch (Exception ex) { } try { if (con != null) { con.close(); } } catch (Exception ex) { } } return w; }
From source file:edu.cmu.lti.oaqa.openqa.hello.eval.passage.PassageMAPEvalPersistenceProvider.java
@Override public Multimap<Key, PassageMAPCounts> retrievePartialCounts(final ExperimentKey experiment) { String select = getSelectPassageAggregates(); final Multimap<Key, PassageMAPCounts> counts = LinkedHashMultimap.create(); RowCallbackHandler handler = new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { Key key = new Key(rs.getString("experimentId"), new Trace(rs.getString("traceId")), rs.getInt("stage")); PassageMAPCounts cnt = new PassageMAPCounts(rs.getFloat("docavep"), rs.getFloat("psgavep"), rs.getFloat("aspavep"), rs.getInt("count")); counts.put(key, cnt);/* w ww. j a va 2s. c om*/ } }; DataStoreImpl.getInstance().jdbcTemplate().query(select, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, experiment.getExperiment()); ps.setInt(2, experiment.getStage()); } }, handler); return counts; }
From source file:org.mskcc.cbio.portal.dao.DaoGistic.java
/** * * Extracts Gistic JDBC Results.//from w w w . j a va 2 s.co m * @param rs Result Set of a JDBC database query * @return Gistic * @throws SQLException * @throws DaoException */ private static Gistic extractGistic(Connection con, ResultSet rs) throws DaoException { // get the genes from the SQL gistic_to_gene table // associated with a particular GISTIC_ROI_ID PreparedStatement pstmt; ResultSet _rs = null; Gistic gistic; ArrayList<CanonicalGene> genes = new ArrayList<CanonicalGene>(); try { int id = rs.getInt("GISTIC_ROI_ID"); pstmt = con.prepareStatement("SELECT * FROM gistic_to_gene WHERE GISTIC_ROI_ID = ?"); pstmt.setInt(1, id); _rs = pstmt.executeQuery(); while (_rs.next()) { long entrez = _rs.getLong("ENTREZ_GENE_ID"); CanonicalGene gene = DaoGeneOptimized.getInstance().getGene(entrez); genes.add(gene); } // create gistic return object gistic = new Gistic(rs.getInt("CANCER_STUDY_ID"), rs.getInt("CHROMOSOME"), rs.getString("CYTOBAND"), rs.getInt("WIDE_PEAK_START"), rs.getInt("WIDE_PEAK_END"), rs.getFloat("Q_VALUE"), genes, rs.getBoolean("AMP")); } catch (SQLException e) { throw new DaoException(e); } finally { JdbcUtil.closeAll(_rs); } return gistic; }