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:org.spc.ofp.data.Repository.java

public static Double readDouble(final ResultSet rs, final String columnName) throws SQLException {
    final double value = rs.getDouble(columnName);
    return rs.wasNull() ? null : Double.valueOf(value);
}

From source file:UpdateableRs.java

public static void printRs(ResultSet rs) throws SQLException {
    rs.beforeFirst();//from  ww w  .ja  va 2 s.  com

    while (rs.next()) {
        int ssn = rs.getInt("ssn");
        String name = rs.getString("name");
        double salary = rs.getDouble("salary");

        System.out.print("Row Number=" + rs.getRow());
        System.out.print(", SSN: " + ssn);
        System.out.print(", Name: " + name);
        System.out.println(", Salary: $" + salary);
    }
    System.out.println();
}

From source file:org.jw.service.factory.StatisticsChartFactory.java

public static CategoryDataset createCategoryDataset(Connection conn, String query) throws SQLException {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement statement = conn.createStatement();
    ResultSet resultSet = statement.executeQuery(query);

    while (resultSet.next()) {
        Double value = resultSet.getDouble("value");
        String series = resultSet.getString("series");
        String category = resultSet.getString("category");
        dataset.addValue(value, series, category);
    }/*from w  w w . j  a v a 2  s  .com*/

    return dataset;
}

From source file:org.apache.derbyDemo.scores.proc.Functions.java

/**
 * <p>/*from w  w  w. j  a v a2s . co  m*/
 * Calculate the median score achieved on a Test.
 * </p>
 */
public static double getMedianTestScore(int testID) throws SQLException {
    Logger log = Logger.getLogger();
    boolean loggingEnabled = log.isLoggingEnabled();
    Median median = new Median();
    ArrayList arraylist = new ArrayList();
    Connection conn = getDefaultConnection();

    try {
        log.enableLogging(false);

        PreparedStatement ps = Utils.prepare(conn, "select tk.score\n" + "from TestTaking tk, LastTaking lt\n"
                + "where tk.takingID = lt.takingID\n" + "and tk.testID = ?\n");

        ps.setInt(1, testID);

        ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            arraylist.add(new Double(rs.getDouble(1)));
        }

        Utils.close(rs);
        Utils.close(ps);
    } finally {
        log.enableLogging(loggingEnabled);
    }

    int count = arraylist.size();
    double values[] = new double[count];

    for (int i = 0; i < count; i++) {
        values[i] = ((Double) arraylist.get(i)).doubleValue();
    }

    return median.evaluate(values);
}

From source file:com.l2jfree.sql.L2DatabaseInstaller.java

private static double getDatabaseRevision() {
    double revision = -1;

    Connection con = null;/* ww  w  . j a  v  a 2 s . com*/
    try {
        con = L2Database.getConnection();

        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT revision FROM _revision ORDER BY revision DESC LIMIT 1");

        if (rs.next())
            revision = rs.getDouble(1);

        rs.close();
        st.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        L2Database.close(con);
    }

    return revision;
}

From source file:fr.eo.util.dumper.JSONDumper.java

private static Object getFieldValue(RequestDefinitionBean request, int pos, ResultSet rs, String fieldName)
        throws SQLException {
    String str = String.valueOf(rs.getObject(fieldName)).trim();
    if (str.endsWith(".0")) {
        str = str.substring(0, str.length() - 2);
    }/*ww  w.  j a v a 2s.co m*/
    if (str.equals("null") || str.isEmpty()) {
        return null;
    }
    if (request.compressedStrPos.contains(pos)) {
        str = getCompressedString(str);
    } else if (request.numberPos.contains(pos)) {
        Number number = rs.getDouble(fieldName);
        if (number.longValue() == number.doubleValue()) {
            return number.longValue();
        }
        return number.doubleValue();
    } else if (request.fieldStrPos.contains(pos)) {
        str = formatString(str);
    }

    return str;
}

From source file:bullioneconomy.bullionchart.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset./*from w w  w.ja va 2s  .  co m*/
 */
private static XYDataset createDataset() throws ClassNotFoundException, SQLException, ParseException {

    TimeSeries s1 = new TimeSeries("Actual", Day.class);
    TimeSeries s2 = new TimeSeries("Forecasted", Day.class);
    Class.forName("com.mysql.jdbc.Driver");
    try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/BULLION", "yajnab",
            "petrol123")) {
        Statement stmt = con.createStatement();
        ResultSet result = stmt.executeQuery("SELECT * FROM gold");
        ArrayList<Double> arm = new ArrayList<>();
        predictor pcd = new predictor();
        arm = pcd.ARIMApredict();
        int i = 0;
        while (result.next()) {

            String datefeed = result.getString(1);
            Double value = result.getDouble(2);
            int[] m = new int[3];
            //bullionchart bcc = new bullionchart();
            //m = bcc.dateget(datefeed);
            m = dateget(datefeed);
            s1.add(new Day(m[0], m[1], m[2]), value);
            s2.add(new Day(m[0], m[1], m[2]), arm.get(i));
            i++;
        }
        result.close();
        /*s1.add(new Month(2, 2001), 181.8);
        s1.add(new Month(3, 2001), 167.3);
        s1.add(new Month(4, 2001), 153.8);
        s1.add(new Month(5, 2001), 167.6);
        s1.add(new Month(6, 2001), 158.8);
        s1.add(new Month(7, 2001), 148.3);
        s1.add(new Month(8, 2001), 153.9);
        s1.add(new Month(9, 2001), 142.7);
        s1.add(new Month(10, 2001), 123.2);
        s1.add(new Month(11, 2001), 131.8);
        s1.add(new Month(12, 2001), 139.6);
        s1.add(new Month(1, 2002), 142.9);
        s1.add(new Month(2, 2002), 138.7);
        s1.add(new Month(3, 2002), 137.3);
        s1.add(new Month(4, 2002), 143.9);
        s1.add(new Month(5, 2002), 139.8);
        s1.add(new Month(6, 2002), 137.0);
        s1.add(new Month(7, 2002), 132.8);*/
    }

    /*TimeSeries s2 = new TimeSeries("Forecasted", Month.class);
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);*/

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    dataset.setDomainIsPointsInTime(true);

    return dataset;

}

From source file:Data.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//w  ww .  j av  a 2  s . c  om
 * @throws ClassNotFoundException 
 */
private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException {

    TimeSeries s1 = new TimeSeries("Humidit");
    TimeSeries s2 = new TimeSeries("Temprature");
    ResultSet rs = null;

    try {
        String sqlRequest = "SELECT * FROM `t_temphum`";
        rs = stmt.executeQuery(sqlRequest);
        Double hum;
        Double temp;
        Timestamp date;

        while (rs.next()) {
            hum = rs.getDouble("tmp_humidity");
            temp = rs.getDouble("tmp_temperature");
            date = rs.getTimestamp("tmp_date");

            if (tempUnit == "F") {
                temp = celsiusToFahrenheit(temp.toString());
            }

            if (date != null) {
                s1.add(new Second(date), hum);
                s2.add(new Second(date), temp);
            } else {
                JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne",
                        "Date null", JOptionPane.WARNING_MESSAGE);
            }
        }

        rs.close();
    } catch (SQLException e) {
        String exception = e.toString();

        if (e.getErrorCode() == 0) {
            JOptionPane.showMessageDialog(panelPrincipal,
                    "Le serveur met trop de temps  rpondre ! Veuillez rssayer plus tard ou contacter un administrateur",
                    "Connection timed out", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception,
                    "Titre : exception", JOptionPane.ERROR_MESSAGE);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (Exception e) {
        String exception = e.toString();
        JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    return dataset;

}

From source file:fr.eo.util.dumper.Dumper.java

private static String getFieldValue(RequestDefinitionBean request, int pos, ResultSet rs, String fieldName)
        throws SQLException {
    String str = String.valueOf(rs.getObject(fieldName)).trim();
    if (str.endsWith(".0")) {
        str = str.substring(0, str.length() - 2);
    }/*from   ww w  .ja va  2s  .co m*/
    if (str.equals("null") || str.isEmpty()) {
        return "NULL";
    }
    if (request.compressedStrPos.contains(pos)) {
        str = getCompressedString(str);
    } else if (request.numberPos.contains(pos)) {
        Double number = rs.getDouble(fieldName);
        str = nf.format(number);
    } else if (request.fieldStrPos.contains(pos)) {
        str = formatString(str);
    }

    return str;
}

From source file:com.act.lcms.db.model.CuratedChemical.java

protected static List<CuratedChemical> fromResultSet(ResultSet resultSet) throws SQLException {
    List<CuratedChemical> results = new ArrayList<>();
    while (resultSet.next()) {
        Integer id = resultSet.getInt(DB_FIELD.ID.getOffset());
        String name = resultSet.getString(DB_FIELD.NAME.getOffset());
        String inchi = resultSet.getString(DB_FIELD.INCHI.getOffset());
        Double mass = resultSet.getDouble(DB_FIELD.MASS.getOffset());
        Integer expectedCollisionVoltage = resultSet.getInt(DB_FIELD.EXPECTED_COLLISION_VOLTAGE.getOffset());
        if (resultSet.wasNull()) {
            expectedCollisionVoltage = null;
        }//from   w  w  w. j  a v a2 s.  c  om
        String referenceUrl = resultSet.getString(DB_FIELD.REFERENCE_URL.getOffset());

        results.add(new CuratedChemical(id, name, inchi, mass, expectedCollisionVoltage, referenceUrl));
    }

    return results;
}