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.imagelake.control.PaymentPreferenceDAOImp.java

public double getMinEarnings() {
    double d = 0;
    try {/*from w w w. j  ava 2 s  .  c  o m*/
        String sql = "SELECT * FROM min_earning";
        PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            d = rs.getDouble(2);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return d;
}

From source file:fitmon.WorkoutData.java

public ArrayList<ArrayList> getTotalCaloriesBurned(int userId) throws SQLException {
    PreparedStatement st = null;/*from   w  w  w.j av a 2 s  .c  o m*/
    Connection conn = null;
    ArrayList<ArrayList> calBurnedList = new ArrayList<ArrayList>();
    try {
        String query = "select date,sum(calories) from Workout where userId=" + userId
                + " group by date limit 5";
        Class.forName("com.mysql.jdbc.Driver");
        conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/fitmon", "root",
                "april-23");
        st = conn.prepareStatement(query);
        conn.setAutoCommit(false);

        ArrayList calBurned = new ArrayList();
        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {
            calBurned = new ArrayList();
            calBurned.add(rs.getString("date"));
            calBurned.add(rs.getDouble("sum(calories)"));
            calBurnedList.add(calBurned);
        }
        st.close();
        conn.close();

    } catch (ClassNotFoundException ce) {
        ce.printStackTrace();
    } catch (SQLException se) {
        se.printStackTrace();
    } catch (Exception e) {
        //Handle errors for Class.forName
        e.printStackTrace();
    } finally {

        if (st != null) {
            st.close();
        }

        if (conn != null) {
            conn.close();
        }

    }

    return calBurnedList;
}

From source file:com.fufang.testcase.ep.supplierapi.SaveOrUpdateAll.java

@Test
public void updateMed() throws ClientProtocolException, IOException, SQLException {

    Map<String, String> data = new HashMap<String, String>();
    data.put("barcode", "????005");
    data.put("matcode", matCode);
    data.put("batchNum", "?005");
    data.put("name", "??005");
    data.put("commonName", "??005");
    data.put("spec", "005");
    data.put("unit", "??005");
    data.put("dosage", "005");
    data.put("licenseNum", "?005");
    data.put("manufName", "005");
    data.put("prodPlace", "?005");
    data.put("productDate", "2012-12-15");
    data.put("validDate", "2013-12-15");
    data.put("retailPrice", "15.5");
    data.put("zhongbao", "5");
    data.put("createPerson", "?005");
    data.put("sellState", "n");
    data.put("manufNameAbbr", "");
    data.put("is_kcbxs", "?");
    data.put("price", "5.5");
    data.put("storeNum", "150");

    JSONArray dataArray = JSONArray.fromObject(data);
    JSONObject params = new JSONObject();
    params.put("key", "875FC66B-0422-4E0A-B0CE-F1C47BF3E1B5");
    params.put("data", dataArray);
    String sParams = params.toString();
    JsonUtils.printJson(sParams);/*from  w  w w .ja  v  a 2s.c o  m*/

    String resultContent = HttpUtils.httpPostJson(url, sParams);
    System.out.println(" - " + resultContent);

    JSONObject jsonObject = JSONObject.fromObject(resultContent);
    String code = jsonObject.getString("code");
    JSONObject responseData = jsonObject.getJSONObject("data");
    String result = responseData.getString("result");
    String dataCode = responseData.getString("code");

    Assert.assertEquals("000000", code);
    Assert.assertEquals("??????", result);
    Assert.assertEquals("SUCCESS", dataCode);

    SqlUtils c = new SqlUtils();
    con = c.sqlSConnection(dbUrl, dbName, dbUserName, dbPassword);

    try {
        Statement statement = con.createStatement();
        String querySqlM = "SELECT * FROM [wit_selection].[zc_sumMaterial] where matcode = '" + matCode + "'";
        ResultSet resultSetM = statement.executeQuery(querySqlM);
        while (resultSetM.next()) {
            String barcode = resultSetM.getString("barcode");
            System.out.println(barcode);
            Assert.assertEquals(barcode, "????005");
            //??
        }

        String querySqlP = "SELECT * FROM [wit_selection].[zc_sumPriceAndNum] where matcode = '" + matCode
                + "'";
        ResultSet resultSetP = statement.executeQuery(querySqlP);
        while (resultSetP.next()) {
            double price = resultSetP.getDouble("price");
            System.out.println(price);
            Assert.assertEquals(5.5, price);
            //??
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fuel.gui.stats.StationStatsPanel.java

private void refreshGraphs() {
    graphContainer.removeAll();/*w w w  . j  ava2  s. c o  m*/
    DefaultPieDataset usageDataset = new DefaultPieDataset();
    try {
        for (Station station : database.getStations()) {
            ResultSet thisStation = database
                    .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true);
            thisStation.next();
            usageDataset.setValue(station.toString(), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false);
    PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot();
    plot3.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel usagePieChartPanel = new ChartPanel(usagePieChart);
    usagePieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding")));
    usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultPieDataset fuelDataset = new DefaultPieDataset();
    try {
        ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true);
        while (numberResults.next()) {
            ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '"
                    + numberResults.getString("typeOfGas") + "'", true);
            thisStation.next();
            fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1"));
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }
    JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false);
    PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot();
    plot2.setForegroundAlpha(0.6f);
    //plot3.setCircular(true);

    JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart);
    fuelPieChartPanel.setBorder(
            BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding")));
    fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    DefaultCategoryDataset barDataset = new DefaultCategoryDataset();
    try {
        ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC",
                true);
        while (motorThing.next()) {
            barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter");
        }

    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause());
    }

    JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title
            "", // domain axis label
            "Aantal", // range axis label
            barDataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = barChart.getCategoryPlot();
    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ChartPanel barChartPanel = new ChartPanel(barChart);
    barChartPanel.getChartRenderingInfo().setEntityCollection(null);
    barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter"));
    barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240));

    JPanel piePanel = new JPanel(new GridLayout(0, 2));
    piePanel.add(usagePieChartPanel);
    piePanel.add(fuelPieChartPanel);
    graphContainer.add(piePanel);
    graphContainer.add(barChartPanel);
    revalidate();
    repaint();
}

From source file:com.fufang.testcase.ep.supplierapi.SaveOrUpdateAll.java

@Test
public void saveMed() throws ClientProtocolException, IOException, SQLException {

    //json/*from   w  w w . j a  v a2s  . c o  m*/
    Map<String, String> data = new HashMap<String, String>();
    data.put("barcode", "????004");
    data.put("matcode", matCode);
    data.put("batchNum", "?004");
    data.put("name", "??004");
    data.put("commonName", "??004");
    data.put("spec", "004");
    data.put("unit", "??004");
    data.put("dosage", "004");
    data.put("licenseNum", "?004");
    data.put("manufName", "004");
    data.put("prodPlace", "?004");
    data.put("productDate", "2012-12-12");
    data.put("validDate", "2013-12-13");
    data.put("retailPrice", "14.4");
    data.put("zhongbao", "4");
    data.put("createPerson", "?004");
    data.put("sellState", "y");
    data.put("manufNameAbbr", "");
    data.put("is_kcbxs", "");
    data.put("price", "14.4");
    data.put("storeNum", "100");

    JSONArray dataArray = JSONArray.fromObject(data);
    JSONObject params = new JSONObject();
    params.put("key", "875FC66B-0422-4E0A-B0CE-F1C47BF3E1B5");
    params.put("data", dataArray);
    String sParams = params.toString();
    JsonUtils.printJson(sParams);//?json

    String resultContent = HttpUtils.httpPostJson(url, sParams);
    System.out.println(" - " + resultContent);

    JSONObject jsonObject = JSONObject.fromObject(resultContent);
    String code = jsonObject.getString("code");
    JSONObject responseData = jsonObject.getJSONObject("data");
    String result = responseData.getString("result");
    String dataCode = responseData.getString("code");

    Assert.assertEquals("000000", code);
    Assert.assertEquals("??????", result);
    Assert.assertEquals("SUCCESS", dataCode);

    SqlUtils c = new SqlUtils();
    con = c.sqlSConnection(dbUrl, dbName, dbUserName, dbPassword);

    //??
    try {
        Statement statement = con.createStatement();
        String querySql = "SELECT * FROM [wit_selection].[zc_sumMaterial] where matcode = '" + matCode + "'";
        ResultSet resultSet = statement.executeQuery(querySql);
        //resultSet.absolute(1);

        while (resultSet.next()) {
            String barcode = resultSet.getString("barcode");
            System.out.println(barcode);

            Assert.assertEquals(barcode, "????004");
            //??
        }
        String querySqlP = "SELECT * FROM [wit_selection].[zc_sumPriceAndNum] where matcode = '" + matCode
                + "'";
        ResultSet resultSetP = statement.executeQuery(querySqlP);
        while (resultSetP.next()) {
            double price = resultSetP.getDouble("price");
            System.out.println(price);
            Assert.assertEquals(14.4, price);
            //??
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.karki.spring.dao.impl.CourseDaoImpl.java

private Course mapData(ResultSet rs) throws SQLException {
    Course course = new Course();
    course.setId(rs.getInt("id"));
    course.setCourseName(rs.getString("course_name"));
    course.setCourseDescription(rs.getString("course_description"));
    course.setDurationType(rs.getString("duration_type"));
    course.setFees(rs.getDouble("fees"));
    course.setDuration(rs.getInt("duration"));
    course.setAddedDate(rs.getDate("added_date"));
    course.setModifiedDate(rs.getDate("modified_date"));
    course.setStatus(rs.getBoolean("status"));
    return course;
}

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

@Override
public Criteria get(int criteriaId) {
    String sql = "SELECT criteria.id, criteria.criteria_value,criteria.weight_factor, criteria.formula, caption.argument,criteria.foreign_to_therm "
            + "FROM intermediate " + "INNER JOIN geology.caption "
            + "ON geology.intermediate.foreign_to_caption=geology.caption.Id " + "INNER JOIN geology.criteria "
            + "ON geology.intermediate.foreign_to_criteria=geology.criteria.Id " + "where criteria.Id="
            + criteriaId + ";";
    return jdbcTemplate.query(sql, new ResultSetExtractor<Criteria>() {

        @Override//from w  w  w.  j av  a2  s . co  m
        public Criteria extractData(ResultSet rs) throws SQLException, DataAccessException {
            Criteria criteria = new Criteria();
            if (rs.next()) {
                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"));
                criteria.setTherms(rs.getInt("foreign_to_therm"));
            }
            return criteria;
        }
    });
}

From source file:com.bs.beans.SalesBean.java

public void cTotalPrice(int c) {
    Connection con = DB.getConnection();
    try {/* ww w . ja v  a  2  s.  c o  m*/
        PreparedStatement stm = con.prepareStatement("select Sales_Price from prices where Id=" + c + " ");
        ResultSet rs = stm.executeQuery();
        if (rs.next()) {
            totalPrice[c] = rs.getDouble(1) * qty[c];
            gtotal += totalPrice[c];
        }
        rs.close();
        con.close();
    } catch (Exception e) {
        try {
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(SalesBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

From source file:com.autentia.tnt.bill.migration.support.OriginalInformationRecoverer.java

/**
 * Recupera la suma total de todos los conceptos de cada una de las facturas cuyo tipo se envia por parametro
 * @param billType tipo de factura/*  ww  w .  j  a  va 2s.c o  m*/
 */
public static double[] getImporteFacturaOriginal(String billType) throws Exception {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    LineNumberReader file = null;
    double[] result = new double[0];

    try {
        log.info("RECOVERING IMPORTE FACTURAS " + billType + " ORIGINALES");

        // connect to database
        Class.forName(BillToBillPaymentMigration.DATABASE_DRIVER);
        con = DriverManager.getConnection(BillToBillPaymentMigration.DATABASE_CONNECTION,
                BillToBillPaymentMigration.DATABASE_USER, BillToBillPaymentMigration.DATABASE_PASS); //NOSONAR
        con.setAutoCommit(false); //DATABASE_PASS vacio.            

        String sql = "SELECT sum((bb.units*bb.amount)*(1+(bb.iva/100))) as total from Bill b left join BillBreakDown bb on b.id=bb.billId, Organization o, Project p where b.projectId = p.id and p.organizationId = o.id and b.billType= ? group by b.id order by total";

        pstmt = con.prepareStatement(sql);

        rs = pstmt.executeQuery();
        pstmt.setString(1, billType);

        rs.last();
        result = new double[rs.getRow()];
        rs.beforeFirst();
        int counter = 0;

        while (rs.next()) {
            result[counter] = rs.getDouble(1);
            log.info("\t" + result[counter]);
            counter++;
        }
        con.commit();
    } catch (Exception e) {
        log.error("FAILED: WILL BE ROLLED BACK: ", e);
        if (con != null) {
            con.rollback();
        }
    } finally {
        cierraFichero(file);
        liberaConexion(con, pstmt, rs);
    }
    return result;
}

From source file:at.plechinger.minigeocode.mapper.GeocodeRowMapper.java

@Override
public GeocodeResult mapRow(ResultSet row, int index) throws SQLException {
    GeocodeResult result = new GeocodeResult();
    result.setStreet(row.getString("street"));
    result.setHousenumber(row.getString("housenumber"));
    result.setPostcode(row.getString("postcode"));
    result.setCity(row.getString("city"));
    result.setCountry(row.getString("country"));

    result.setLongitude(row.getDouble("longitude"));
    result.setLatitude(row.getDouble("latitude"));

    return result;
}