Example usage for java.sql ResultSet getBigDecimal

List of usage examples for java.sql ResultSet getBigDecimal

Introduction

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

Prototype

BigDecimal getBigDecimal(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.math.BigDecimal with full precision.

Usage

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public Purchase getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE purchase_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Purchase>() {

        @Override// w w  w.  j av  a2 s  .c  o m
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:com.softserveinc.internetbanking.model.mapper.MoneyTransactionRowMapper.java

@Override
public MoneyTransaction mapRow(ResultSet rs, int i) throws SQLException {
    MoneyTransaction moneyTransaction = new MoneyTransaction();
    moneyTransaction.setAccount_id(rs.getInt("account_id"));
    moneyTransaction.setDateTime(rs.getString("date_time"));
    moneyTransaction.setDestination_account_id(rs.getInt("destination_account_id"));
    moneyTransaction.setTransactionAmount(rs.getBigDecimal("amount"));
    moneyTransaction.setTransactionId(rs.getInt("transaction_id"));
    return moneyTransaction;
}

From source file:org.springframework.batch.sample.CompositeItemWriterSampleFunctionalTests.java

private void checkOutputTable(int before) {
    @SuppressWarnings("serial")
    final List<Trade> trades = new ArrayList<Trade>() {
        {// www .  j a  v  a  2s .c  o  m
            add(new Trade("UK21341EAH41", 211, new BigDecimal("31.11"), "customer1"));
            add(new Trade("UK21341EAH42", 212, new BigDecimal("32.11"), "customer2"));
            add(new Trade("UK21341EAH43", 213, new BigDecimal("33.11"), "customer3"));
            add(new Trade("UK21341EAH44", 214, new BigDecimal("34.11"), "customer4"));
            add(new Trade("UK21341EAH45", 215, new BigDecimal("35.11"), "customer5"));
        }
    };

    int after = jdbcTemplate.queryForObject("SELECT COUNT(*) from TRADE", Integer.class);

    assertEquals(before + 5, after);

    jdbcTemplate.query(GET_TRADES, new RowCallbackHandler() {
        private int activeRow = 0;

        @Override
        public void processRow(ResultSet rs) throws SQLException {
            Trade trade = trades.get(activeRow++);

            assertEquals(trade.getIsin(), rs.getString(1));
            assertEquals(trade.getQuantity(), rs.getLong(2));
            assertEquals(trade.getPrice(), rs.getBigDecimal(3));
            assertEquals(trade.getCustomer(), rs.getString(4));
        }
    });

}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public List<Purchase> getALL(boolean status) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE 1=1";

    if (status) {
        sql += " AND status=1 ";
    }/*  w  w w  . j  a  v  a  2 s.c o m*/
    return jdbcTemplate.query(sql, new RowMapper<Purchase>() {

        @Override
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:me.j360.idgen.impl.SequenceIdGenServiceImpl.java

/**
 * Gets the next id as a Big Decimal. This method will only be called when
 * synchronized and when the data type is configured to be BigDecimal.
 * //from   w w  w . j av  a2s  .  com
 * @return the next id as a BigDecimal.
 * @throws IdCreationException
 */
protected BigDecimal getNextBigDecimalIdInner() {
    getLogger().debug("[IDGeneration Service] Requesting an Id using query: {}", query);
    try {
        // 2009.10.08 - without handling connection directly
        Connection conn = DataSourceUtils.getConnection(getDataSource());
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            stmt = conn.prepareStatement(query);
            rs = stmt.executeQuery();
            if (rs.next()) {
                return rs.getBigDecimal(1);
            } else {
                getLogger().error(
                        "[IDGeneration Service] Unable to allocate a block of Ids. Query for Id did not return a value.");
                throw new IdCreationException(
                        "[IDGeneration Service] Unable to allocate a block of Ids. Query for Id did not return a value.");
            }
        } finally {
            if (rs != null) {
                JdbcUtils.closeResultSet(rs);
            }
            if (stmt != null) {
                JdbcUtils.closeStatement(stmt);
            }
            // 2009.10.08 - without handling connection directly
            if (conn != null) {
                DataSourceUtils.releaseConnection(conn, getDataSource());
            }

        }
        // 2009.10.08 - without handling connection directly
    } catch (Exception ex) {
        if (ex instanceof IdCreationException)
            throw (IdCreationException) ex;
        getLogger().error(
                "[IDGeneration Service] We can't get a connection. So, unable to allocate a block of Ids.", ex);
        throw new IdCreationException(
                "[IDGeneration Service] We can't get a connection. So, unable to allocate a block of Ids.", ex);
    }
}

From source file:org.castor.cpa.test.test12.TestTypeConversion.java

public void testValuesInDB() throws Exception {
    LOG.debug("Test values in database");
    // Create a statement and a resultset
    _db.begin();//  www .  ja  v a  2  s  .  co  m
    Connection conn = _db.getJdbcConnection();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select bool_int, " + "bool_int_minus, bool_bigdec, bool_bigdec_minus "
            + "from test12_conv where id = " + TypeConversion.DEFAULT_ID);
    rs.next();
    BigDecimal bigPlus = rs.getBigDecimal("bool_bigdec");
    BigDecimal bigMinus = rs.getBigDecimal("bool_bigdec_minus");
    if ((rs.getInt("bool_int") != 1) && (rs.getInt("bool_int_minus") != -1)
            && !bigPlus.equals(new BigDecimal(1)) && !bigMinus.equals(new BigDecimal(-1))) {

        LOG.error(REASON);
        fail(REASON);
    }
    _db.commit();
    LOG.debug("OK: Found the expected Values in database");
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SalesDAOImpl.java

@Override
public Sales getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_sales WHERE sales_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Sales>() {

        @Override//w  w w .  ja  va 2 s. c  om
        public Sales mapRow(ResultSet rs, int i) throws SQLException {
            Sales s = new Sales();
            s.setId(rs.getInt("sales_id"));
            s.setProductId(rs.getInt("product_id"));
            s.setSellingPrice(rs.getInt("selling_price"));
            s.setQuantity(rs.getInt("quantity"));
            s.setDiscount(rs.getBigDecimal("discount"));
            s.setTotalCost(rs.getInt("total_cost"));
            s.setSalesDate(rs.getDate("sales_date"));
            s.setPaymentMethod(rs.getString("payment_method"));
            s.setStatus(rs.getBoolean("status"));
            return s;
        }
    });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.SalesDAOImpl.java

@Override
public List<Sales> getALL(boolean status) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_sales WHERE 1=1";

    if (status) {
        sql += " AND status=1 ";
    }/* w  w w.j  a  v  a 2 s.  co  m*/
    return jdbcTemplate.query(sql, new RowMapper<Sales>() {

        @Override
        public Sales mapRow(ResultSet rs, int i) throws SQLException {
            Sales s = new Sales();
            s.setId(rs.getInt("sales_id"));
            s.setProductId(rs.getInt("product_id"));
            s.setSellingPrice(rs.getInt("selling_price"));
            s.setQuantity(rs.getInt("quantity"));
            s.setDiscount(rs.getBigDecimal("discount"));
            s.setTotalCost(rs.getInt("total_cost"));
            s.setSalesDate(rs.getDate("sales_date"));
            s.setPaymentMethod(rs.getString("payment_method"));
            s.setStatus(rs.getBoolean("status"));

            return s;
        }
    });
}

From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportProfessionalRegimesFromGiaf.java

@Override
public void processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception {
    int updatedRegimes = 0;
    int newRegimes = 0;

    PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance();
    String query = getQuery();//from  www  .  java  2 s  .  c  o  m
    PreparedStatement preparedStatement = oracleConnection.prepareStatement(query);
    ResultSet result = preparedStatement.executeQuery();
    while (result.next()) {
        String giafId = result.getString("emp_regime");
        String regimeName = result.getString("regime_dsc");
        Integer weighting = result.getInt("regime_pond");
        BigDecimal fullTimeEquivalent = result.getBigDecimal("valor_eti");

        CategoryType categoryType = null;
        if (!StringUtils.isBlank(regimeName)) {
            if (regimeName.contains("Bolseiro")) {
                categoryType = CategoryType.GRANT_OWNER;
            } else if (regimeName.contains("Investigador")) {
                categoryType = CategoryType.RESEARCHER;
            } else if (regimeName.contains("Pessoal no Docente") || regimeName.contains("Pess. no Doc.")
                    || regimeName.contains("Pessoal No Docente")) {
                categoryType = CategoryType.EMPLOYEE;
            } else if (regimeName.contains("(Docentes)") || regimeName.contains("(Doc)")) {
                categoryType = CategoryType.TEACHER;
            }
        }

        ProfessionalRegime professionalRegime = metadata.regime(giafId);
        MultiLanguageString name = new MultiLanguageString(MultiLanguageString.pt, regimeName);
        if (professionalRegime != null) {
            if (!isEqual(professionalRegime, name, weighting, fullTimeEquivalent, categoryType)) {
                professionalRegime.edit(name, weighting, fullTimeEquivalent, categoryType);
                updatedRegimes++;
            }
        } else {
            metadata.registerRegime(giafId, weighting, fullTimeEquivalent, categoryType, name);
            newRegimes++;
        }
    }
    result.close();
    preparedStatement.close();
    oracleConnection.closeConnection();
    log.printf("Regimes: %d updated, %d new\n", updatedRegimes, newRegimes);
}

From source file:de.tu_berlin.dima.oligos.db.oracle.OracleColumnConnector.java

/**
 * Retrieves the raw histogram from the Oracle Database catalog regardless of its type (i.e. frequency, height
 * balanced, or hybrid histogram). Cumulative frequencies are converted to absolute frequencies.
 * <br />//w  w  w  .j ava2s  . c o m
 * For example
 * <pre>
 *   value 1  1
 *   value 2  2
 *   value 3  3
 *   value 4  4
 *   ...
 * </pre>
 * is converted to
 * <pre>
 *   value 1  1
 *   value 2  1
 *   value 3  1
 *   value 4  1
 *   ...
 * </pre>.
 * <br />
 * The entries are ordered by there respective endpoint_number (before conversion).
 * @return Mapping of values (bucket boundaries) to there apsolute count and repeat count if present.
 * @throws SQLException
 */
@SuppressWarnings("unchecked")
public Map<T, Pair<Long, Long>> getRawHistogram() throws SQLException {
    if (rawHistogram == null) {
        rawHistogram = new LinkedHashMap<>();
        Connection conn = connector.getConnection();
        PreparedStatement stmt = conn.prepareStatement(HISTOGRAM_QUERY);
        stmt.setString(1, schema);
        stmt.setString(2, table);
        stmt.setString(3, column);
        ResultSet result = stmt.executeQuery();
        long last = 0L;
        while (result.next()) {
            BigDecimal endpointValue = result.getBigDecimal("ENDPOINT_VALUE");
            String endpointActualValue = result.getString("ENDPOINT_ACTUAL_VALUE");
            long cumulativeCount = result.getLong("ENDPOINT_NUMBER");
            long endpointRepeatCount = result.getLong("ENDPOINT_REPEAT_COUNT");
            long count = cumulativeCount - last;
            if (getTypeInfo().getType().equals(String.class) && endpointActualValue != null
                    && endpointActualValue.length() > 0) {
                rawHistogram.put(parser.fromString(endpointActualValue), Pair.of(count, endpointRepeatCount));
            } else {
                rawHistogram.put((T) OracleUtils.convertFromNumber(endpointValue, getTypeInfo()),
                        Pair.of(count, endpointRepeatCount));
            }
            last = cumulativeCount;
        }
        stmt.close();
    }
    return rawHistogram;
}