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:lcn.module.batch.web.guide.service.TradeRowMapper.java

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    Trade trade = new Trade(rs.getLong(ID_COLUMN));

    trade.setIsin(rs.getString(ISIN_COLUMN));
    trade.setQuantity(rs.getLong(QUANTITY_COLUMN));
    trade.setPrice(rs.getBigDecimal(PRICE_COLUMN));
    trade.setCustomer(rs.getString(CUSTOMER_COLUMN));
    trade.setVersion(rs.getInt(VERSION_COLUMN));

    return trade;
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.CustomerCreditRowMapper.java

@Override
public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
    CustomerCredit customerCredit = new CustomerCredit();

    customerCredit.setId(rs.getInt(ID_COLUMN));
    customerCredit.setName(rs.getString(NAME_COLUMN));
    customerCredit.setCredit(rs.getBigDecimal(CREDIT_COLUMN));

    return customerCredit;
}

From source file:lcn.module.batch.web.guide.service.CustomerCreditRowMapper.java

/**
 * CustomerCredit VO set//www .  ja  v  a  2s  . c  om
 */
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    CustomerCredit customerCredit = new CustomerCredit();

    customerCredit.setId(rs.getInt(ID_COLUMN));
    customerCredit.setName(rs.getString(NAME_COLUMN));
    customerCredit.setCredit(rs.getBigDecimal(CREDIT_COLUMN));

    return customerCredit;
}

From source file:net.freechoice.model.orm.Map_Account.java

public FC_Account mapRow(final ResultSet rs, int rowNum) throws SQLException {

    FC_Account account = new FC_Account();
    account.id = rs.getInt(1);//  www  . ja v  a 2 s.c  o m
    account.id_user_ = rs.getInt(2);
    account.date_create = rs.getDate(3);
    account.balance = rs.getBigDecimal(4);

    return account;
}

From source file:net.freechoice.model.orm.Map_Transaction.java

@Override
public FC_Transaction mapRow(final ResultSet rs, int rowNum) throws SQLException {

    FC_Transaction transaction = new FC_Transaction();

    transaction.id = rs.getInt(1);/* ww w  .jav  a2  s  .  c  o m*/
    transaction.id_account_ = rs.getInt(2);
    transaction.time_committed = rs.getTimestamp(3);
    transaction.amount = rs.getBigDecimal(4);
    transaction.comment = rs.getString(5);

    return transaction;
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Get the Statement column so that the results are mapped correctly.
 * (this has been copied from AbstractDatabaseAction and modified slightly)
 *///www  . ja  v a 2s .  c o m
public static Object getColumn(ResultSet set, Configuration column) throws Exception {

    Integer type = (Integer) JDBCTypeConversions.typeConstants.get(column.getAttribute("type"));
    String dbcol = column.getAttribute("name");
    Object value = null;

    switch (type.intValue()) {
    case Types.CLOB:
    case Types.CHAR:
        Clob dbClob = set.getClob(dbcol);
        int length = (int) dbClob.length();
        InputStream asciiStream = new BufferedInputStream(dbClob.getAsciiStream());
        byte[] buffer = new byte[length];
        asciiStream.read(buffer);
        String str = new String(buffer);
        asciiStream.close();
        value = str;
        break;
    case Types.BIGINT:
        value = set.getBigDecimal(dbcol);
        break;
    case Types.TINYINT:
        value = new Byte(set.getByte(dbcol));
        break;
    case Types.VARCHAR:
        value = set.getString(dbcol);
        break;
    case Types.DATE:
        value = set.getDate(dbcol);
        break;
    case Types.DOUBLE:
        value = new Double(set.getDouble(dbcol));
        break;
    case Types.FLOAT:
        value = new Float(set.getFloat(dbcol));
        break;
    case Types.INTEGER:
        value = new Integer(set.getInt(dbcol));
        break;
    case Types.NUMERIC:
        value = new Long(set.getLong(dbcol));
        break;
    case Types.SMALLINT:
        value = new Short(set.getShort(dbcol));
        break;
    case Types.TIME:
        value = set.getTime(dbcol);
        break;
    case Types.TIMESTAMP:
        value = set.getTimestamp(dbcol);
        break;
    case Types.ARRAY:
        value = set.getArray(dbcol); // new Integer(set.getInt(dbcol));
        break;
    case Types.BIT:
        value = BooleanUtils.toBooleanObject(set.getBoolean(dbcol));
        break;
    case Types.STRUCT:
        value = (Struct) set.getObject(dbcol);
        break;
    case Types.OTHER:
        value = set.getObject(dbcol);
        break;

    default:
        // The blob types have to be requested separately, via a Reader.
        value = "";
        break;
    }

    return value;
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.JdbcCustomerDao.java

@Override
public CustomerCredit getCustomerByName(String name) {

    List<CustomerCredit> customers = getJdbcTemplate().query(GET_CUSTOMER_BY_NAME, new Object[] { name },

            new RowMapper<CustomerCredit>() {

                @Override// www. j av  a2  s .c om
                public CustomerCredit mapRow(ResultSet rs, int rowNum) throws SQLException {
                    CustomerCredit customer = new CustomerCredit();
                    customer.setName(rs.getString("NAME"));
                    customer.setId(rs.getInt("ID"));
                    customer.setCredit(rs.getBigDecimal("CREDIT"));
                    return customer;
                }

            });

    if (customers.size() == 0) {
        return null;
    } else {
        return customers.get(0);
    }

}

From source file:nl.strohalm.cyclos.utils.hibernate.AmountType.java

public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner)
        throws HibernateException, SQLException {
    final Amount amount = new Amount();
    // If value or type are null, return null
    final BigDecimal value = rs.getBigDecimal(names[0]);
    if (rs.wasNull()) {
        return null;
    }/* ww w  .  j a v  a2 s. c  o m*/
    amount.setValue(value);
    final String type = rs.getString(names[1]);
    if (type == null) {
        return null;
    }
    amount.setType(Amount.Type.getFromValue(type));

    if (LOG.isDebugEnabled()) {
        LOG.debug("Returning " + value + " as column " + names[0]);
        LOG.debug("Returning " + type + " as column " + names[1]);
    }

    return amount;
}

From source file:fi.okm.mpass.shibboleth.profile.impl.StoreMonitoringResultTest.java

protected void assertResult(final Connection connection, final ResultSet set, final int id,
        final long startTime, final long endTime) throws Exception {
    Assert.assertTrue(set.next());//from   w  w  w .j a  v  a  2s  . c o  m
    Assert.assertEquals(id, set.getBigDecimal(1).longValue());
    Assert.assertEquals(startTime, set.getLong("startTime"));
    Assert.assertEquals(endTime, set.getLong("endTime"));
    Assert.assertEquals(sequenceId, set.getString("sourceId"));
    final PreparedStatement getStepResults = connection.prepareStatement("SELECT * from "
            + StoreMonitoringResult.TABLE_NAME_MONITORING_STEP_RESULTS + " where resultId=" + id);
    final ResultSet stepSet = getStepResults.executeQuery();
    Assert.assertTrue(stepSet.next());
    Assert.assertEquals(startTime, stepSet.getLong("startTime"));
    Assert.assertEquals(endTime, stepSet.getLong("endTime"));
    Assert.assertFalse(stepSet.next());
}

From source file:test.Test_User.java

public void xx1() throws SQLException {
    System.out.println(File.separator);

    PreparedStatement ps = cpds.getConnection()
            .prepareStatement("select amount from fc_transaction where id = 12");

    BigDecimal db = new BigDecimal("15.465482652446425");

    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
        BigDecimal b = rs.getBigDecimal(1);
        System.out.println(b.equals(db) + "\n" + b);
    }/*from w  w w .j a v  a  2s .  co m*/
}