Example usage for java.sql ResultSet getDouble

List of usage examples for java.sql ResultSet getDouble

Introduction

In this page you can find the example usage for java.sql ResultSet getDouble.

Prototype

double getDouble(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a double in the Java programming language.

Usage

From source file:com.javacodegags.waterflooding.model.CriteriaImplemented.java

@Override
public List<Criteria> getAll() {
    String sql = "SELECT criteria.id, criteria.criteria_value,criteria.weight_factor, criteria.formula, caption.argument "
            + "                FROM intermediate " + "                INNER JOIN caption "
            + "                ON intermediate.foreign_to_caption=caption.Id "
            + "                INNER JOIN criteria "
            + "                ON intermediate.foreign_to_criteria=criteria.Id";
    List<Criteria> listCriteria = jdbcTemplate.query(sql, new RowMapper<Criteria>() {
        @Override//  w w w.  jav  a 2s.c  o  m
        public Criteria mapRow(ResultSet rs, int rowNum) throws SQLException {
            Criteria criteria = new Criteria();
            criteria.setId(rs.getInt("id"));
            criteria.setValue(rs.getDouble("criteria_value"));
            criteria.setArgument(rs.getDouble("argument"));
            criteria.setFormula(rs.getString("formula"));
            criteria.setWeighFactor(rs.getDouble("weight_factor"));
            return criteria;
        }
    });
    return listCriteria;
}

From source file:com.persistent.cloudninja.mapper.InstanceHealthKpiValueRowMapper.java

@Override
public InstanceHealthKpiValueEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    InstanceHealthKpiValueEntity instanceKPI = new InstanceHealthKpiValueEntity();
    instanceKPI.setInstance(rs.getInt("Instance"));
    instanceKPI.setTimestamp(rs.getString("TimeStamp"));
    instanceKPI.setKpiTypeId(rs.getInt("KpiTypeId"));
    instanceKPI.setValue(rs.getDouble("Value"));
    return instanceKPI;
}

From source file:de.ingrid.importer.udk.strategy.v30.IDCStrategy3_0_0_fixErfassungsgrad.java

private void fixErfassungsgrad() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Fix \"Erfassungsgrad\" (t011_obj_geo.rec_grade) from Commission to Omission...");
    }//from   w  w w . j  a v  a  2s .com

    // sql
    String sql = "select * from t011_obj_geo where rec_grade IS NOT NULL";

    PreparedStatement pS = jdbc.prepareStatement("UPDATE t011_obj_geo SET rec_grade = ? where id = ?");
    Statement st = jdbc.createStatement();
    ResultSet rs = jdbc.executeQuery(sql, st);
    int numFixed = 0;
    while (rs.next()) {
        long id = rs.getLong("id");
        long objId = rs.getLong("obj_id");
        double oldRecGrade = rs.getDouble("rec_grade");
        double newRecGrade = 100.0 - oldRecGrade;
        if (newRecGrade < 0.0) {
            newRecGrade = 0.0;
            log.warn("New value " + newRecGrade + " < 0, we set new value to 0.0.");
        }
        if (newRecGrade > 100.0) {
            newRecGrade = 100.0;
            log.warn("New value " + newRecGrade + " > 100, we set new value to 100.0.");
        }

        try {
            // round 2 decimals after digit
            newRecGrade = new BigDecimal(newRecGrade).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        } catch (Exception ex) {
            log.error("Problems rounding " + newRecGrade
                    + " to 2 decimals after digit, we keep unrounded value." + ex);
        }

        pS.setDouble(1, newRecGrade);
        pS.setLong(2, id);
        int numUpdated = pS.executeUpdate();
        if (log.isDebugEnabled()) {
            log.debug("Fixed t011_obj_geo.rec_grade from " + oldRecGrade + " to " + newRecGrade + " ("
                    + numUpdated + " row(s), objectId: " + objId + ")");
        }
        numFixed++;
    }

    pS.close();
    rs.close();
    st.close();

    if (log.isInfoEnabled()) {
        log.info("Fixed " + numFixed + " times \"Erfassungsgrad\"");
    }

    if (log.isInfoEnabled()) {
        log.info("Fix \"Erfassungsgrad\" (t011_obj_geo.rec_grade) from Commission to Omission...done");
    }
}

From source file:com.mycompany.demos.Servlet3a.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//www .  j a v  a 2s .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:com.app.dao.SearchQueryDAO.java

private static SearchQuery _createSearchQueryFromResultSet(ResultSet resultSet) throws SQLException {

    SearchQuery searchQuery = new SearchQuery();

    searchQuery.setSearchQueryId(resultSet.getInt("searchQueryId"));
    searchQuery.setUserId(resultSet.getInt("userId"));
    searchQuery.setKeywords(resultSet.getString("keywords"));
    searchQuery.setCategoryId(resultSet.getString("categoryId"));
    searchQuery.setSubcategoryId(resultSet.getString("subcategoryId"));
    searchQuery.setSearchDescription(resultSet.getBoolean("searchDescription"));
    searchQuery.setFreeShippingOnly(resultSet.getBoolean("freeShippingOnly"));
    searchQuery.setNewCondition(resultSet.getBoolean("newCondition"));
    searchQuery.setUsedCondition(resultSet.getBoolean("usedCondition"));
    searchQuery.setUnspecifiedCondition(resultSet.getBoolean("unspecifiedCondition"));
    searchQuery.setAuctionListing(resultSet.getBoolean("auctionListing"));
    searchQuery.setFixedPriceListing(resultSet.getBoolean("fixedPriceListing"));
    searchQuery.setMaxPrice(resultSet.getDouble("maxPrice"));
    searchQuery.setMinPrice(resultSet.getDouble("minPrice"));
    searchQuery.setGlobalId(resultSet.getString("globalId"));
    searchQuery.setActive(resultSet.getBoolean("active"));

    return searchQuery;
}

From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.database.AbstractDatabaseService.java

private DataValueDto getValueAsDataSourceValueDoubleWeb(ResultSet row, String columnName) throws SQLException {
    Double value = row.getDouble(row.findColumn(columnName));
    return new DataValueDto<Double>().setValue(value);
}

From source file:funcoes.funcoes.java

@SuppressWarnings("rawtypes")
public static Vector<Comparable> proximaLinha(ResultSet rs, ResultSetMetaData rsmd) throws SQLException {
    Vector<Comparable> LinhaAtual = new Vector<Comparable>();

    try {//  w w  w  .  j av  a  2 s  .  c  om
        for (int i = 1; i <= rsmd.getColumnCount(); ++i) {
            switch (rsmd.getColumnType(i)) {

            case Types.VARCHAR:
                LinhaAtual.addElement(rs.getString(i));
                break;
            case Types.TIMESTAMP:
                LinhaAtual.addElement(rs.getDate(i).toLocaleString().substring(0, 10));
                break;
            case Types.INTEGER:
                LinhaAtual.addElement(rs.getInt(i));
                break;
            case Types.DECIMAL:
                LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i)));
                break;
            case Types.DOUBLE:
                LinhaAtual.addElement(funcoes.paraFormatoDinheiro(rs.getDouble(i)));
                break;

            }
        }
    } catch (SQLException e) {
    }
    return LinhaAtual;

}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.BulkLoaderUnclassifier.java

private Double getLatestCSVersion(UnloadProperties unloadProperties) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String csName = unloadProperties.getClassificationSchemeName();

    Double latestVersion = (Double) jdbcTemplate.query(csLatestVersionQry, new Object[] { csName },
            new ResultSetExtractor() {

                @Override/*from  www  .  j  ava2 s  . c om*/
                public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
                    if (rs.next()) {
                        return new Double(rs.getDouble(1));
                    }
                    return new Double(0.0);
                }
            });

    return latestVersion;
}

From source file:gov.nih.nci.ncicb.cadsr.bulkloader.util.BulkLoaderUnclassifier.java

private Double getLatestCSIVersion(UnloadProperties unloadProperties) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    String csName = unloadProperties.getClassificationSchemeName();
    String csiName = unloadProperties.getClassificationSchemeItemName();

    Double latestVersion = (Double) jdbcTemplate.query(csiLatestVersionQry, new Object[] { csiName, csName },
            new ResultSetExtractor() {

                @Override//from  ww  w  .j  ava  2 s  .c om
                public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
                    if (rs.next()) {
                        return new Double(rs.getDouble(1));
                    }
                    return new Double(0.0);
                }
            });

    return latestVersion;
}

From source file:conexaoBanco.GerenciarProduto.java

public ArrayList getProdutos(Integer vendedor) {
    ArrayList produtos = new ArrayList();
    if (con != null) {
        try {/*  w  w  w.  j  a v  a 2s.  c om*/
            PreparedStatement stmt = con
                    .prepareStatement("SELECT * FROM produtos where vendedor = " + vendedor);
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                Produto produto = new Produto();
                produto.setCodigo(rs.getInt("codigo"));
                produto.setNome(rs.getString("nome"));
                produto.setPreco(rs.getDouble("preco"));
                produto.setImagem(rs.getString("imagem"));
                produto.setDescricao(rs.getString("descricao"));
                produtos.add(produto);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return produtos;
}