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:CSVWriter.java

private static String getColumnValue(ResultSet rs, int colType, int colIndex)
    throws SQLException, IOException {

  String value = "";
      /*from   www . j a v a  2 s  . c  om*/
switch (colType)
{
  case Types.BIT:
    Object bit = rs.getObject(colIndex);
    if (bit != null) {
      value = String.valueOf(bit);
    }
  break;
  case Types.BOOLEAN:
    boolean b = rs.getBoolean(colIndex);
    if (!rs.wasNull()) {
      value = Boolean.valueOf(b).toString();
    }
  break;
  case Types.CLOB:
    Clob c = rs.getClob(colIndex);
    if (c != null) {
      value = read(c);
    }
  break;
  case Types.BIGINT:
  case Types.DECIMAL:
  case Types.DOUBLE:
  case Types.FLOAT:
  case Types.REAL:
  case Types.NUMERIC:
    BigDecimal bd = rs.getBigDecimal(colIndex);
    if (bd != null) {
      value = "" + bd.doubleValue();
    }
  break;
  case Types.INTEGER:
  case Types.TINYINT:
  case Types.SMALLINT:
    int intValue = rs.getInt(colIndex);
    if (!rs.wasNull()) {
      value = "" + intValue;
    }
  break;
  case Types.JAVA_OBJECT:
    Object obj = rs.getObject(colIndex);
    if (obj != null) {
      value = String.valueOf(obj);
    }
  break;
  case Types.DATE:
    java.sql.Date date = rs.getDate(colIndex);
    if (date != null) {
      value = DATE_FORMATTER.format(date);;
    }
  break;
  case Types.TIME:
    Time t = rs.getTime(colIndex);
    if (t != null) {
      value = t.toString();
    }
  break;
  case Types.TIMESTAMP:
    Timestamp tstamp = rs.getTimestamp(colIndex);
    if (tstamp != null) {
      value = TIMESTAMP_FORMATTER.format(tstamp);
    }
  break;
  case Types.LONGVARCHAR:
  case Types.VARCHAR:
  case Types.CHAR:
    value = rs.getString(colIndex);
  break;
  default:
    value = "";
}

    
if (value == null)
{
  value = "";
}
    
return value;
      
}

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

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

        @Override//from  w ww .j a  v a  2 s.  c om
        public Product mapRow(ResultSet rs, int i) throws SQLException {
            Product p = new Product();
            p.setId(rs.getInt("product_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setSellingPrice(rs.getInt("selling_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setCategoryName(rs.getString("category_name"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setAddedDate(rs.getDate("added_date"));
            p.setModifiedDate(rs.getDate("modified_date"));
            p.setStatus(rs.getBoolean("status"));
            return p;
        }
    });
}

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

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

    if (inStock) {
        sql += " AND status=1 ";
    }//w  w w  .  ja v  a2 s. co  m
    return jdbcTemplate.query(sql, new RowMapper<Product>() {

        @Override
        public Product mapRow(ResultSet rs, int i) throws SQLException {
            Product p = new Product();
            p.setId(rs.getInt("product_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setSellingPrice(rs.getInt("selling_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setCategoryName(rs.getString("category_name"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setAddedDate(rs.getDate("added_date"));
            p.setModifiedDate(rs.getDate("modified_date"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:com.webbfontaine.valuewebb.report.ScanSelectivityReporter.java

private int createCells(ResultSet rs, Map<String, CellStyle> cellStyleMap, Sheet sheet) throws SQLException {
    int rowNumber = DEFAULT_STARTING_ROW_NUMBER;
    while (rs.next()) {
        Row sheetRow = sheet.createRow(rowNumber);
        createCell(sheetRow, 'A', rs.getBigDecimal("tt_id"), cellStyleMap.get("GENERAL_CENTER_TEXT_STYLE"));
        createCell(sheetRow, 'B', rs.getString("crt_cod1"), cellStyleMap.get("GENERAL_LEFT_TEXT_STYLE"));
        createCell(sheetRow, 'C', rs.getString("crt_cod2"), cellStyleMap.get("GENERAL_CENTER_TEXT_STYLE"));
        createCell(sheetRow, 'D', rs.getBigDecimal("num_of_cont"), cellStyleMap.get("CENTER_DIGIT_CELL_STYLE"));
        createCell(sheetRow, 'E', rs.getString("dai_num"), cellStyleMap.get("GENERAL_LEFT_TEXT_STYLE"));
        createCell(sheetRow, 'F', rs.getString("bl_num"), cellStyleMap.get("GENERAL_LEFT_TEXT_STYLE"));
        createCell(sheetRow, 'G', rs.getString("prod_description"),
                cellStyleMap.get("GENERAL_LEFT_TEXT_STYLE"));
        createCell(sheetRow, 'H', rs.getBigDecimal("declared_quantity"),
                cellStyleMap.get("GENERAL_RIGHT_NUMBER_STYLE"));
        createCell(sheetRow, 'I', rs.getString("d_unit"), cellStyleMap.get("GENERAL_CENTER_TEXT_STYLE"));
        createCell(sheetRow, 'J', rs.getBigDecimal("trs_grs_wgt"),
                cellStyleMap.get("GENERAL_CENTER_NUMBER_STYLE"));
        createCell(sheetRow, 'K', rs.getBigDecimal("trs_net_wgt"),
                cellStyleMap.get("GENERAL_CENTER_NUMBER_STYLE"));
        createCell(sheetRow, 'L', rs.getString("hit_date"), cellStyleMap.get("GENERAL_CENTER_TEXT_STYLE"));
        rowNumber++;//from   ww w.  j  a  v a2 s.  c  om
    }
    return rowNumber;
}

From source file:nl.tudelft.stocktrader.derby.DerbyMarketSummaryDAO.java

public Quote getQuoteForUpdate(String symbol) throws DAOException {
    if (logger.isDebugEnabled()) {
        logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :" + symbol);
    }/*from  ww w .  jav a 2  s  .c o  m*/
    PreparedStatement qouteForUpdateStat = null;
    try {
        qouteForUpdateStat = sqlConnection.prepareStatement(SQL_SELECT_QUOTE);
        Quote quote = null;

        qouteForUpdateStat.setString(1, symbol);
        ResultSet rs = qouteForUpdateStat.executeQuery();

        if (rs.next()) {
            quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                    rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));

            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
            return quote;
        } else {
            throw new DAOException("No quote entry found");
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        try {
            if (qouteForUpdateStat != null) {
                qouteForUpdateStat.close();
            }
        } catch (SQLException e) {
            logger.debug("", e);
        }
    }
}

From source file:nl.tudelft.stocktrader.derby.DerbyMarketSummaryDAO.java

public Quote getQuote(String symbol) throws DAOException {
    if (logger.isDebugEnabled()) {
        logger.debug("MarketSummaryDAO.getQouteForUpdate(String)\nSymbol :" + symbol);
    }/*  ww  w .  j av  a2  s  . c o m*/
    PreparedStatement selectQuote = null;
    try {
        selectQuote = sqlConnection.prepareStatement(SQL_SELECT_QUOTE_NOLOCK);
        selectQuote.setString(1, symbol);
        ResultSet rs = selectQuote.executeQuery();

        try {
            Quote quote = null;
            if (rs.next()) {
                quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));
            }
            return quote;
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        try {
            if (selectQuote != null) {
                selectQuote.close();
            }
        } catch (SQLException e) {
            logger.debug("", e);
        }
    }
}

From source file:it.jnrpe.plugin.CCheckOracle.java

/**
 * Checks cache hit rates//www .java2 s.co  m
 * @param c
 * @param cl
 * @return
 */
private CReturnValue checkCache(Connection c, CCommandLine cl) {
    String sWarning = cl.getOptionValue("warning", "70");
    String sCritical = cl.getOptionValue("critical", "80");

    String sQry1 = "select (1-(pr.value/(dbg.value+cg.value)))*100"
            + " from v$sysstat pr, v$sysstat dbg, v$sysstat cg" + " where pr.name='physical reads'"
            + " and dbg.name='db block gets'" + " and cg.name='consistent gets'";

    String sQry2 = "select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 from v$librarycache lc";

    Statement stmt = null;
    ResultSet rs = null;

    try {
        stmt = c.createStatement();

        rs = stmt.executeQuery(sQry1);
        rs.next();

        BigDecimal buf_hr = rs.getBigDecimal(1);

        rs = stmt.executeQuery(sQry2);
        rs.next();

        BigDecimal lib_hr = rs.getBigDecimal(1);

        String sMessage = "{0} {1} - Cache Hit Rates: {2,number,0.#}% Lib -- {3,number,0.#}% Buff|lib={4,number,0.#}%;{5};{6};0;100 buffer={3,number,0.#};{5};{6};0;100";

        MessageFormat mf = new MessageFormat(sMessage);

        Object[] vValues = new Object[7];
        vValues[0] = cl.getOptionValue("db");
        vValues[1] = "OK";
        vValues[2] = lib_hr;
        vValues[3] = buf_hr;
        vValues[4] = lib_hr;
        vValues[5] = sWarning;
        vValues[6] = sCritical;

        //if (buf_hr.compareTo(new BigDecimal(iCritical.intValue())) == -1)
        if (ThresholdUtil.isValueInRange(sCritical, buf_hr)) {
            vValues[1] = "CRITICAL";

            CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vValues));
            return rv;
        }

        //if (buf_hr.compareTo(new BigDecimal(iWarning.intValue())) == -1)
        if (ThresholdUtil.isValueInRange(sWarning, buf_hr)) {
            vValues[1] = "WARNING";

            CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vValues));

            return rv;
        }

        CReturnValue rv = new CReturnValue(IJNRPEConstants.STATE_WARNING, mf.format(vValues));

        return rv;

    } catch (Exception e) {
        return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, "CHECK_ORACLE : CRITICAL - " + e.getMessage());
    } finally {
        try {
            stmt.close();
            rs.close();
        } catch (Exception e) {
        }
    }

}

From source file:nl.tudelft.stocktrader.mysql.MySQLMarketSummaryDAO.java

public MarketSummary getCustomMarketSummary() throws DAOException {
    BigDecimal tSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_TSIA,
            sqlConnection);//from w  w w  . j a  v  a  2s  .  c o m
    BigDecimal openTSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_OPENTSIA,
            sqlConnection);
    double totalVolume = ((Double) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_VOLUME,
            sqlConnection)).doubleValue();

    List<Quote> topGainers = new ArrayList<Quote>();
    PreparedStatement gainers = null;
    try {
        gainers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_GAINERS);
        ResultSet rs = gainers.executeQuery();

        try {
            for (int i = 0; rs.next() && i < 5; i++) {
                Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));
                topGainers.add(quote);
            }
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        if (gainers != null) {
            try {
                gainers.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    List<Quote> topLosers = new ArrayList<Quote>();
    PreparedStatement losers = null;
    try {
        losers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_LOSERS);
        ResultSet rs = losers.executeQuery();

        try {
            for (int i = 0; rs.next() && i < 5; i++) {
                Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));
                topLosers.add(quote);
            }
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        if (losers != null) {
            try {
                losers.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    MarketSummary marketSummary = new MarketSummary(tSIA, openTSIA, totalVolume, topGainers, topLosers);
    return marketSummary;
}

From source file:nl.tudelft.stocktrader.derby.DerbyMarketSummaryDAO.java

public MarketSummary getCustomMarketSummary() throws DAOException {
    BigDecimal tSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_TSIA,
            sqlConnection);/*from  w ww.j a v  a2 s.c o  m*/
    BigDecimal openTSIA = (BigDecimal) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_OPENTSIA,
            sqlConnection);
    double totalVolume = ((Float) StockTraderSQLUtil.executeScalarNoParm(SQL_SELECT_MARKETSUMMARY_VOLUME,
            sqlConnection)).doubleValue();

    List<Quote> topGainers = new ArrayList<Quote>();
    PreparedStatement gainers = null;
    try {
        gainers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_GAINERS);
        ResultSet rs = gainers.executeQuery();

        try {
            for (int i = 0; rs.next() && i < 5; i++) {
                Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));
                topGainers.add(quote);
            }
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        if (gainers != null) {
            try {
                gainers.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    List<Quote> topLosers = new ArrayList<Quote>();
    PreparedStatement losers = null;
    try {
        losers = sqlConnection.prepareStatement(SQL_SELECT_MARKETSUMMARY_LOSERS);
        ResultSet rs = losers.executeQuery();

        try {
            for (int i = 0; rs.next() && i < 5; i++) {
                Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));
                topLosers.add(quote);
            }
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        if (losers != null) {
            try {
                losers.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    }
    MarketSummary marketSummary = new MarketSummary(tSIA, openTSIA, totalVolume, topGainers, topLosers);
    return marketSummary;
}

From source file:nl.tudelft.stocktrader.derby.DerbyMarketSummaryDAO.java

public List<Quote> getAllQuotes() throws DAOException {
    if (logger.isDebugEnabled()) {
        logger.debug("MarketSummaryDAO.getAllQuotes()");
    }/*  www .jav  a 2  s  . c o m*/
    PreparedStatement selectQuote = null;
    try {
        selectQuote = sqlConnection.prepareStatement(SQL_SELECT_ALL_QUOTES);
        ResultSet rs = selectQuote.executeQuery();

        try {
            ArrayList<Quote> quotes = new ArrayList<Quote>();
            while (rs.next()) {
                Quote quote = new Quote(rs.getString(1), rs.getString(2), rs.getDouble(3), rs.getBigDecimal(4),
                        rs.getBigDecimal(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getDouble(8));

                quotes.add(quote);
            }
            return quotes;
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
                logger.debug("", e);
            }
        }
    } catch (SQLException e) {
        throw new DAOException("", e);
    } finally {
        try {
            if (selectQuote != null) {
                selectQuote.close();
            }
        } catch (SQLException e) {
            logger.debug("", e);
        }
    }

}