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:ca.qc.adinfo.rouge.achievement.db.AchievementDb.java

public static HashMap<String, Achievement> getAchievementList(DBManager dbManager) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    HashMap<String, Achievement> returnValue = new HashMap<String, Achievement>();

    String sql = "SELECT `key`, `name`, `point_value`, `total` FROM rouge_achievements";
    try {/*from  w w w  .j  av a 2 s  . c  om*/
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);

        rs = stmt.executeQuery();

        while (rs.next()) {

            String key = rs.getString("key");

            Achievement achievement = new Achievement(key, rs.getString("name"), rs.getInt("point_value"),
                    rs.getDouble("total"), 0);

            returnValue.put(key, achievement);
        }

        return returnValue;

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return null;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:ca.qc.adinfo.rouge.achievement.db.AchievementDb.java

public static HashMap<String, Achievement> getAchievements(DBManager dbManager, long userId) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    HashMap<String, Achievement> returnValue = new HashMap<String, Achievement>();

    String sql = "SELECT ach.`key` as `key`, ach.`name` as name, " + "ach.point_value as point_value, "
            + "prg.progress as progress, ach.total as total "
            + "FROM rouge_achievement_progress as prg, rouge_achievements as ach "
            + "WHERE ach.key = prg.achievement_key and prg.user_id = ?; ";

    try {/*from w  w w  .j a v a  2s .  co m*/
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);
        stmt.setLong(1, userId);

        rs = stmt.executeQuery();

        while (rs.next()) {

            String key = rs.getString("key");

            Achievement achievement = new Achievement(key, rs.getString("name"), rs.getInt("point_value"),
                    rs.getDouble("total"), rs.getDouble("progress"));

            returnValue.put(key, achievement);
        }

        return returnValue;

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return null;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

From source file:com.pamarin.income.model.rowmapper.StatisticRowMapper.java

@Override
public Statistic mapRow(ResultSet rs, int i) throws SQLException {
    return new Statistic(rs.getString("income_name"), rs.getDouble("income_value"));
}

From source file:at.alladin.rmbt.db.fields.DoubleField.java

@Override
public void setField(final ResultSet rs) throws SQLException {
    value = rs.getDouble(dbKey);
    if (rs.wasNull())
        value = null;//  www. j  a v  a  2 s  .  c  om
}

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

/**
 * Recupera la suma total de todos los conceptos de todas las facturas del tipo que se envie por parametro
 * @param billType tipo de factura/* w  w w  . java 2  s .  c  o m*/
 */
public static double getTotalFacturasMigrated(String billType) throws Exception {

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    LineNumberReader file = null;
    double result = -1;

    try {
        log.info("RECOVERING TOTAL FACTURAS " + billType + " MIGRADAS");

        // 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 es nula               

        String sql = "SELECT sum(bp.amount) FROM BillPayment bp, Bill b where bp.billId = b.id and b.billType = ?";
        pstmt = con.prepareStatement(sql);
        pstmt.setString(1, billType);

        rs = pstmt.executeQuery();
        while (rs.next()) {
            result = rs.getDouble(1);
            log.info("\t" + result);
        }

    } 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:com.google.visualization.datasource.util.SqlDataSourceHelper.java

/**
 * Creates a table cell from the value in the current row of the given result
 * set and the given column index. The type of the value is determined by the
 * given value type.//from  w  ww. j a va 2s .c  o m
 *
 * @param rs The result set holding the data from the sql table. The result
 *     points to the current row.
 * @param valueType The value type of the column that the cell belongs to.
 * @param column The column index. Indexes are 0-based.
 *
 * @return The table cell.
 *
 * @throws SQLException Thrown when the connection to the database failed.
 */
private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException {
    Value value = null;

    // SQL indexes are 1- based.
    column = column + 1;

    switch (valueType) {
    case BOOLEAN:
        value = BooleanValue.getInstance(rs.getBoolean(column));
        break;
    case NUMBER:
        value = new NumberValue(rs.getDouble(column));
        break;
    case DATE:
        Date date = rs.getDate(column);
        // If date is null it is handled later.
        if (date != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month and date in the gregorian calendar.
            // Use the 'set' method with those parameters, and not the 'setTime'
            // method with the date parameter, since the Date object contains the
            // current time zone and it's impossible to change it to 'GMT'.
            gc.set(date.getYear() + 1900, date.getMonth(), date.getDate());
            value = new DateValue(gc);
        }
        break;
    case DATETIME:
        Timestamp timestamp = rs.getTimestamp(column);
        // If timestamp is null it is handled later.
        if (timestamp != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the year, month, date, hours, minutes and seconds in the
            // gregorian calendar. Use the 'set' method with those parameters,
            // and not the 'setTime' method with the timestamp parameter, since
            // the Timestamp object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(),
                    timestamp.getMinutes(), timestamp.getSeconds());
            // Set the milliseconds explicitly, as they are not saved in the
            // underlying date.
            gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000);
            value = new DateTimeValue(gc);
        }
        break;
    case TIMEOFDAY:
        Time time = rs.getTime(column);
        // If time is null it is handled later.
        if (time != null) {
            GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
            // Set the hours, minutes and seconds of the time in the gregorian
            // calendar. Set the year, month and date to be January 1 1970 like
            // in the Time object.
            // Use the 'set' method with those parameters,
            // and not the 'setTime' method with the time parameter, since
            // the Time object contains the current time zone and it's
            // impossible to change it to 'GMT'.
            gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds());
            // Set the milliseconds explicitly, otherwise the milliseconds from
            // the time the gc was initialized are used.
            gc.set(GregorianCalendar.MILLISECOND, 0);
            value = new TimeOfDayValue(gc);
        }
        break;
    default:
        String colValue = rs.getString(column);
        if (colValue == null) {
            value = TextValue.getNullValue();
        } else {
            value = new TextValue(rs.getString(column));
        }
        break;
    }
    // Handle null values.
    if (rs.wasNull()) {
        return new TableCell(Value.getNullValueFromValueType(valueType));
    } else {
        return new TableCell(value);
    }
}

From source file:com.wabacus.system.datatype.DoubleType.java

public Object getColumnValue(ResultSet rs, int iindex, AbsDatabaseType dbtype) throws SQLException {
    return Double.valueOf(rs.getDouble(iindex));
}

From source file:com.wabacus.system.datatype.DoubleType.java

public Object getColumnValue(ResultSet rs, String column, AbsDatabaseType dbtype) throws SQLException {
    return Double.valueOf(rs.getDouble(column));
}

From source file:id.aas.apps.mvc.view.barChart.java

public void setChart() throws SQLException {
    double Lunas = 0;
    double Casbon = 0;
    String queryLunas = "SELECT SUM(total_tagihan) from transaksi where keterangan='Lunas'";
    String queryCasbon = "SELECT SUM(total_tagihan) from transaksi where keterangan='Cash Bon'";
    ConnectionDB.InstanceDB.openConnection();
    ResultSet rs = ConnectionDB.InstanceDB.RunSelectQuery(queryLunas);
    while (rs.next()) {
        Lunas = rs.getDouble(1);
    }/*from w ww. j  a  v  a  2s  .c o  m*/
    System.out.println(Lunas);

    ResultSet rs1 = ConnectionDB.InstanceDB.RunSelectQuery(queryCasbon);
    while (rs1.next()) {
        Casbon = rs1.getDouble(1);
    }
    System.out.println(Casbon);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(Lunas, "Lunas", "Catatan Uang Pendapatan");
    dataset.setValue(Casbon, "Cash Bon", "Catatan Uang Pendapatan");

    JFreeChart chart = ChartFactory.createBarChart3D("Catatan Uang Pendapatan dan Piutang",
            "Keterangan Pembayaran", "Jumlah Uang", dataset);
    ChartPanel cPanel = new ChartPanel(chart);
    this.setContentPane(cPanel);
}

From source file:com.springapp.mvc.mappers.PriceRowMapper.java

@Override
public PriceRow mapRow(ResultSet resultSet, int i) throws SQLException {
    PriceRow priceRow = new PriceRow();

    priceRow.setCode(resultSet.getInt("code"));
    priceRow.setAmount(resultSet.getDouble("amount"));
    priceRow.setStartDate(resultSet.getDate("startdate"));
    priceRow.setEndDate(resultSet.getDate("enddate"));
    priceRow.setCurrency(Currency.getInstance(resultSet.getString("currency")));

    return priceRow;

}