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.mskcc.cbio.cgds.dao.DaoGistic.java
/** * * Extracts Gistic JDBC Results./*from w ww .j a v a 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 = null; 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(pstmt, _rs); } return gistic; }
From source file:staff.Waiter.MenuController.java
@FXML private void onClickgetMenuButton(ActionEvent e) { ObservableList<Menu> list = FXCollections.observableArrayList(); try {//from www . j av a 2s. c o m Statement st = conn.createStatement(); String query = "select * from menu"; ResultSet rs = st.executeQuery(query); int f = 0; while (rs.next()) { f++; Menu a = new Menu(rs.getInt("d_id"), rs.getString("d_name"), rs.getFloat("price"), "0"); list.add(a); } if (f != 0) menutable.getItems().addAll(list); } catch (SQLException ex) { Logger.getLogger(CurrentOrderController.class.getName()).log(Level.SEVERE, null, ex); } getListButton.setDisable(false); couponTextField.setEditable(true); }
From source file:com.l2jfree.gameserver.datatables.LevelUpData.java
private LevelUpData() { _lvlTable = new FastMap<Integer, L2LvlupData>(); Connection con = null;//from ww w .ja va2 s . c o m try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement(SELECT_ALL); ResultSet rset = statement.executeQuery(); L2LvlupData lvlDat; while (rset.next()) { lvlDat = new L2LvlupData(); lvlDat.setClassid(rset.getInt(CLASS_ID)); lvlDat.setClassLvl(rset.getInt(CLASS_LVL)); lvlDat.setClassHpBase(rset.getFloat(HP_BASE)); lvlDat.setClassHpAdd(rset.getFloat(HP_ADD)); lvlDat.setClassHpModifier(rset.getFloat(HP_MOD)); lvlDat.setClassCpBase(rset.getFloat(CP_BASE)); lvlDat.setClassCpAdd(rset.getFloat(CP_ADD)); lvlDat.setClassCpModifier(rset.getFloat(CP_MOD)); lvlDat.setClassMpBase(rset.getFloat(MP_BASE)); lvlDat.setClassMpAdd(rset.getFloat(MP_ADD)); lvlDat.setClassMpModifier(rset.getFloat(MP_MOD)); _lvlTable.put(lvlDat.getClassid(), lvlDat); } rset.close(); statement.close(); _log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates."); } catch (Exception e) { _log.error("error while creating Lvl up data table ", e); } finally { L2DatabaseFactory.close(con); } }
From source file:fr.in2p3.cc.storage.treqs.persistence.mysql.dao.MySQLConfigurationDAO.java
@Override public MultiMap getResourceAllocation() throws TReqSException { LOGGER.trace("> getResourceAllocation"); // Allocations maps a media type to a pair (user,share) final MultiMap allocations = new MultiValueMap(); final Object[] objects = MySQLBroker.getInstance().executeSelect(MySQLStatements.SQL_ALLOCATIONS_SELECT); // Store result final ResultSet result = (ResultSet) objects[1]; try {/*from w w w . j av a2s . c o m*/ while (result.next()) { int index = 1; final byte id = result.getByte(index++); final String userName = result.getString(index++); final float share = result.getFloat(index++); final PersistenceHelperResourceAllocation helper = new PersistenceHelperResourceAllocation(userName, share); allocations.put(new Byte(id), helper); LOGGER.debug("Allocation on mediatype: '" + id + "', user: '" + userName + "', share: " + share); } } catch (final SQLException exception) { throw new MySQLExecuteException(exception); } finally { MySQLBroker.getInstance().terminateExecution(objects); } if (allocations.size() == 0) { // No entry in table, something wrong with configuration. LOGGER.warn("No media type allocations found. Please define them " + "in the database."); } LOGGER.trace("< getResourceAllocation"); return allocations; }
From source file:com.mycompany.demos.Servlet3a.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a v a 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; final String DB_URL = "jdbc:mysql://localhost:3306/garbagecollectionv2"; final String USER = "root"; final String PASS = "1234"; double lat = 0, lng = 0; float fullness = 0; int locationId, binId, depotId, numOfVehicles; JSONObject bins, feature, properties, geometry; JSONArray features, coordinates; features = new JSONArray(); Connection conn = null; Statement stmt = null; try { //STEP 2: Register JDBC driver System.out.println("Loading Driver..."); Class.forName(JDBC_DRIVER); //STEP 3: Open a connection System.out.println("Connecting to database..."); conn = DriverManager.getConnection(DB_URL, USER, PASS); //STEP 4: Execute a query System.out.println("Creating statement..."); stmt = conn.createStatement(); String sql; sql = "SELECT * FROM bins inner join locations on bins.locationId = locations.locationId;"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { lat = rs.getDouble("lat"); lng = rs.getDouble("lng"); fullness = rs.getFloat("fullness"); locationId = rs.getInt("locationId"); binId = rs.getInt("binId"); //System.out.println(fullness); coordinates = new JSONArray(); coordinates.add(lng); coordinates.add(lat); geometry = new JSONObject(); geometry.put("type", "Point"); geometry.put("coordinates", coordinates); properties = new JSONObject(); properties.put("locationId", locationId); properties.put("binId", binId); properties.put("fullness", fullness); properties.put("type", "bin"); feature = new JSONObject(); feature.put("type", "Feature"); feature.put("geometry", geometry); feature.put("properties", properties); features.add(feature); } sql = "SELECT * FROM depots inner join locations on depots.locationId = locations.locationId;"; rs = stmt.executeQuery(sql); while (rs.next()) { lat = rs.getDouble("lat"); lng = rs.getDouble("lng"); numOfVehicles = rs.getInt("numOfVehicles"); locationId = rs.getInt("locationId"); depotId = rs.getInt("depotId"); //System.out.println(fullness); coordinates = new JSONArray(); coordinates.add(lng); coordinates.add(lat); geometry = new JSONObject(); geometry.put("type", "Point"); geometry.put("coordinates", coordinates); properties = new JSONObject(); properties.put("locationId", locationId); properties.put("numOfVehicles", numOfVehicles); properties.put("depotId", depotId); properties.put("type", "depot"); feature = new JSONObject(); feature.put("type", "Feature"); feature.put("geometry", geometry); feature.put("properties", properties); features.add(feature); } rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException se2) { } try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } } bins = new JSONObject(); bins.put("type", "FeatureCollection"); bins.put("features", features); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(bins.toString()); System.out.println(bins.toString()); }
From source file:org.georepublic.db.utils.ResultSetConverter.java
public static JSONArray convert(ResultSet rs) throws SQLException, JSONException { JSONArray json = new JSONArray(); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { int numColumns = rsmd.getColumnCount(); JSONObject obj = new JSONObject(); for (int i = 1; i < numColumns + 1; i++) { String column_name = rsmd.getColumnName(i); if (rsmd.getColumnType(i) == java.sql.Types.ARRAY) { obj.put(column_name, rs.getArray(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BIGINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BOOLEAN) { obj.put(column_name, rs.getBoolean(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.BLOB) { obj.put(column_name, rs.getBlob(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DOUBLE) { obj.put(column_name, rs.getDouble(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.FLOAT) { obj.put(column_name, rs.getFloat(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.INTEGER) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.NVARCHAR) { obj.put(column_name, rs.getNString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.VARCHAR) { obj.put(column_name, rs.getString(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TINYINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.SMALLINT) { obj.put(column_name, rs.getInt(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.DATE) { obj.put(column_name, rs.getDate(column_name)); } else if (rsmd.getColumnType(i) == java.sql.Types.TIMESTAMP) { obj.put(column_name, rs.getTimestamp(column_name)); } else { obj.put(column_name, rs.getObject(column_name)); }/*from w ww . jav a 2s . c o m*/ } json.put(obj); } return json; }
From source file:com.oracle.tutorial.jdbc.CoffeesTable.java
public void modifyPrices(float percentage) throws SQLException { Statement stmt = null;//from www.j ava 2s . co m try { stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES"); while (uprs.next()) { float f = uprs.getFloat("PRICE"); uprs.updateFloat("PRICE", f * percentage); uprs.updateRow(); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:org.apache.hadoop.chukwa.rest.services.ClusterSystemMetricsHome.java
private static ClusterSystemMetrics createClusterSystemMetrics(ResultSet rs) { ClusterSystemMetrics obj = null;//from w w w.j a v a 2s. c om try { obj = new ClusterSystemMetrics(rs.getTimestamp("Timestamp"), rs.getInt("host"), rs.getDouble("load_15"), rs.getDouble("load_5"), rs.getDouble("load_1"), rs.getDouble("task_total"), rs.getDouble("task_running"), rs.getDouble("task_sleep"), rs.getDouble("task_stopped"), rs.getDouble("task_zombie"), rs.getDouble("mem_total"), rs.getDouble("mem_buffers"), rs.getDouble("mem_cached"), rs.getDouble("mem_used"), rs.getDouble("mem_free"), rs.getDouble("eth0_rxerrs"), rs.getDouble("eth0_rxbyts"), rs.getDouble("eth0_rxpcks"), rs.getDouble("eth0_rxdrops"), rs.getDouble("eth0_txerrs"), rs.getDouble("eth0_txbyts"), rs.getDouble("eth0_txpcks"), rs.getDouble("eth0_txdrops"), rs.getDouble("eth1_rxerrs"), rs.getDouble("eth1_rxbyts"), rs.getDouble("eth1_rxpcks"), rs.getDouble("eth1_rxdrops"), rs.getDouble("eth1_txerrs"), rs.getDouble("eth1_txbyts"), rs.getDouble("eth1_txpcks"), rs.getDouble("eth1_txdrops"), rs.getDouble("sda_rkbs"), rs.getDouble("sda_wkbs"), rs.getDouble("sdb_rkbs"), rs.getDouble("sdb_wkbs"), rs.getDouble("sdc_rkbs"), rs.getDouble("sdc_wkbs"), rs.getDouble("sdd_rkbs"), rs.getDouble("sdd_wkbs"), rs.getFloat("cpu_idle_pcnt"), rs.getFloat("cpu_nice_pcnt"), rs.getFloat("cpu_system_pcnt"), rs.getFloat("cpu_user_pcnt"), rs.getFloat("cpu_hirq_pcnt"), rs.getFloat("cpu_sirq_pcnt"), rs.getFloat("iowait_pcnt"), rs.getFloat("mem_buffers_pcnt"), rs.getFloat("mem_used_pcnt"), rs.getFloat("eth0_busy_pcnt"), rs.getFloat("eth1_busy_pcnt"), rs.getFloat("sda_busy_pcnt"), rs.getFloat("sdb_busy_pcnt"), rs.getFloat("sdc_busy_pcnt"), rs.getFloat("sdd_busy_pcnt"), rs.getFloat("swap_used_pcnt")); } catch (Exception e) { } return obj; }
From source file:br.com.asisprojetos.mapper.TBContratoMapper.java
@Override public TBContrato mapRow(ResultSet rs, int rowNum) throws SQLException { TBContrato tbContrato = new TBContrato(); tbContrato.setCodContrato(rs.getInt("COD_CONTRATO")); tbContrato.setCodCliente(rs.getInt("COD_CLIENTE")); tbContrato.setCodVendedor(rs.getInt("COD_VENDEDOR")); tbContrato.setNumContrato(rs.getString("NUM_CONTRATO")); tbContrato.setDataVigenciaIni(rs.getDate("DAT_VIGENCIA_INI")); tbContrato.setDataVigenciaFim(rs.getDate("DAT_VIGENCIA_FIM")); tbContrato.setComissao(rs.getFloat("COMISSAO")); tbContrato.setQtdProcessMes(rs.getInt("QTD_PROCESS_MES")); tbContrato.setQtdProcessAtu(rs.getInt("QTD_PROCESS_ATU")); tbContrato.setDataUltimaAtu(rs.getDate("DAT_ULTIMA_ATU")); tbContrato.setDataCriacao(rs.getDate("DAT_CRIACAO")); tbContrato.setQtdCnpj(rs.getInt("QTD_CNPJ")); tbContrato.setQtdNF(rs.getInt("QTD_NF")); tbContrato.setQtdParcelas(rs.getInt("QTD_PARCELAS")); tbContrato.setValor(rs.getFloat("VALOR")); tbContrato.setInAtivo(StringUtils.equals(rs.getString("IN_ATIVO"), "A")); tbContrato.setFerramenta(rs.getInt("FERRAMENTA")); tbContrato.setPrioridade(rs.getInt("PRIORIDADE")); return tbContrato; }