Java Code Examples for java.sql.ResultSet#getBigDecimal()
The following examples show how to use
java.sql.ResultSet#getBigDecimal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testPercentRankDesc() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts); String query = "SELECT PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at // timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); BigDecimal rank = rs.getBigDecimal(1); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.11, rank.doubleValue(), 0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example 2
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testPercentRankWithNegativeNumeric() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts); String query = "SELECT PERCENT_RANK(-2) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at // timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); BigDecimal rank = rs.getBigDecimal(1); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.0, rank.doubleValue(), 0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example 3
Source File: BigDecimalHandler.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** This method is a wrapper for the ResultSet method getBigDecimal(int columnIndex). * * @param rs ResultSet * @param columnIndex Column Index * @return String value of getXXX(columnIndex)method on the ResultSet * @throws SQLException */ public static String getBigDecimalString(ResultSet rs, int columnIndex) throws SQLException{ String bigDecimalString=null; switch(representation){ case BIGDECIMAL_REPRESENTATION: //Call toString() only for non-null values, else return null if(rs.getBigDecimal(columnIndex) != null) bigDecimalString = rs.getBigDecimal(columnIndex).toString(); break; case STRING_REPRESENTATION: bigDecimalString = rs.getString(columnIndex); int columnType= rs.getMetaData().getColumnType(columnIndex); if((bigDecimalString != null) && !canConvertToDecimal(columnType)) throw new SQLException("Invalid data conversion. Method not called."); break; default: new Exception("Failed: Invalid Big Decimal representation").printStackTrace(); } return bigDecimalString; }
Example 4
Source File: LogMinerSession.java From datacollector with Apache License 2.0 | 5 votes |
/** * Returns the list of redo logs that covers a given range of changes in database. The range is defined as the * interval [start, end) and the list will contain any redo log with some SCN in that range; i.e. it is not necessary * that all the redo log SCNs are in range [start, end). * * @param start Start SCN (inclusive limit). * @param end End SCN (exclusive limit). * @return List of all the redo logs having some SCN in range [start, end). * @throws StageException Database error. */ private List<RedoLog> findLogs(BigDecimal start, BigDecimal end) { List<RedoLog> result = new ArrayList<>(); String query = SELECT_REDO_LOGS_QUERY .replace(SELECT_REDO_LOGS_ARG_FIRST, start.toPlainString()) .replace(SELECT_REDO_LOGS_ARG_NEXT, end.toPlainString()); try (PreparedStatement statement = connection.prepareCall(query)) { ResultSet rs = statement.executeQuery(); while (rs.next()) { RedoLog log = new RedoLog( rs.getString(1), rs.getBigDecimal(2), rs.getBigDecimal(3), rs.getTimestamp(4), rs.getTimestamp(5), rs.getBigDecimal(6), rs.getBigDecimal(7), rs.getBoolean(8), rs.getBoolean(9) ); result.add(log); } } catch (SQLException e) { throw new StageException(JdbcErrors.JDBC_603, e); } return result; }
Example 5
Source File: NonUniqueIndexIT.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
/** * Tests that adding an index to an existing data set will * result in a correct and consistent index * * Basically, add some data to the table, then create the index, * then perform a lookup on that same data via the index to ensure * that the index will find those values. */ @Test(timeout=15000) public void testCanCreateIndexFromExistingDataWithDecimalType() throws Exception{ BigDecimal oid = BigDecimal.valueOf(2); String name = "sfines"; PreparedStatement preparedStatement = methodWatcher.prepareStatement("insert into " + spliceTableWatcher8 + " values (?,?)"); preparedStatement.setBigDecimal(1,oid); preparedStatement.setString(2,name); preparedStatement.execute(); new SpliceIndexWatcher(TABLE_NAME_8,spliceSchemaWatcher.schemaName,INDEX_81,spliceSchemaWatcher.schemaName,"(name)").starting(null); //now check that we can get data out for the proper key preparedStatement = methodWatcher.prepareStatement("select * from "+ spliceTableWatcher8+" where oid = ?"); preparedStatement.setBigDecimal(1,oid); ResultSet resultSet = preparedStatement.executeQuery(); try{ List<String> results = Lists.newArrayListWithExpectedSize(1); while(resultSet.next()){ BigDecimal retOid = resultSet.getBigDecimal(1); String retName = resultSet.getString(2); Assert.assertEquals("Incorrect name returned!",name,retName); Assert.assertEquals("Incorrect oid returned!",oid,retOid); results.add(String.format("name:%s,value:%s",retName,retOid)); } Assert.assertEquals("Incorrect number of rows returned!",1,results.size()); }finally{ resultSet.close(); } }
Example 6
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testPercentileWithGroupbyAndOrderBy() throws Exception { String tenantId = getOrganizationId(); String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) AS PC FROM " + tableName + " GROUP BY A_STRING ORDER BY PC"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals("a",rs.getString(1)); BigDecimal percentile = rs.getBigDecimal(2); percentile = percentile.setScale(1, RoundingMode.HALF_UP); assertEquals(7.0, percentile.doubleValue(),0.0); assertTrue(rs.next()); assertEquals("c",rs.getString(1)); percentile = rs.getBigDecimal(2); percentile = percentile.setScale(1, RoundingMode.HALF_UP); assertEquals(8.0, percentile.doubleValue(),0.0); assertTrue(rs.next()); assertEquals("b",rs.getString(1)); percentile = rs.getBigDecimal(2); percentile = percentile.setScale(1, RoundingMode.HALF_UP); assertEquals(9.0, percentile.doubleValue(),0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example 7
Source File: TradeJDBCDirect.java From jboss-daytrader with Apache License 2.0 | 5 votes |
private QuoteDataBean getQuoteDataFromResultSet(ResultSet rs) throws Exception { QuoteDataBean quoteData = null; quoteData = new QuoteDataBean(rs.getString("symbol"), rs.getString("companyName"), rs.getDouble("volume"), rs .getBigDecimal("price"), rs.getBigDecimal("open1"), rs.getBigDecimal("low"), rs.getBigDecimal("high"), rs.getDouble("change1")); return quoteData; }
Example 8
Source File: TradeDirect.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
private HoldingDataBean getHoldingDataFromResultSet(ResultSet rs) throws Exception { HoldingDataBean holdingData = null; holdingData = new HoldingDataBean(new Integer(rs.getInt("holdingID")), rs.getDouble("quantity"), rs.getBigDecimal("purchasePrice"), rs.getTimestamp("purchaseDate"), rs.getString("quote_symbol")); return holdingData; }
Example 9
Source File: ProjectRestrictOperationIT.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testArithmeticOperators() throws Exception{ ResultSet rs=methodWatcher.executeQuery("select sc,sd,se, sd-sc,sd+sc,sd*sc,se/sd from "+spliceTableWatcher2+" where true"); List<String> results=Lists.newArrayList(); while(rs.next()){ int sc=rs.getInt(1); int sd=rs.getInt(2); BigDecimal se=rs.getBigDecimal(3); int diff=rs.getInt(4); int sum=rs.getInt(5); int mult=rs.getInt(6); BigDecimal div=rs.getBigDecimal(7); int correctDiff=sd-sc; int correctSum=sd+sc; int correctMult=sd*sc; BigDecimal correctDiv=se.divide(new BigDecimal(sd),MIN_DECIMAL_DIVIDE_SCALE,BigDecimal.ROUND_DOWN); Assert.assertEquals("Incorrect diff!",correctDiff,diff); Assert.assertEquals("Incorrect sum!",correctSum,sum); Assert.assertEquals("Incorrect mult!",correctMult,mult); // SPLICE-898 Assert.assertEquals("Incorrect Div!",correctDiv.compareTo(div),0); results.add(String.format("sc=%d,sd=%d,se=%f,diff=%d,sum=%d,mult=%d,div=%f%n",sc,sd,se,diff,sum,mult,div)); } for(String result : results){ LOG.info(result); } Assert.assertEquals("incorrect rows returned",10,results.size()); }
Example 10
Source File: BigIntegerTypeHandler.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public BigInteger getNullableResult(ResultSet rs, int columnIndex) throws SQLException { BigDecimal b = rs.getBigDecimal(columnIndex); return b != null ? TypeConverters.convert(b, BigInteger.class) : null; }
Example 11
Source File: TradeDirect.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
private AccountDataBean getAccountDataFromResultSet(ResultSet rs) throws Exception { AccountDataBean accountData = null; if (!rs.next()) { Log.error("TradeDirect:getAccountDataFromResultSet -- cannot find account data"); } else { accountData = new AccountDataBean(new Integer(rs.getInt("accountID")), rs.getInt("loginCount"), rs.getInt("logoutCount"), rs.getTimestamp("lastLogin"), rs.getTimestamp("creationDate"), rs.getBigDecimal("balance"), rs.getBigDecimal("openBalance"), rs.getString("profile_userID")); } return accountData; }
Example 12
Source File: TPCETradeResult.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
protected void invokeFrame3() throws SQLException { BigDecimal tax_rates; PreparedStatement ps= conn.prepareStatement(selectTaxRate); ps.setLong(1, cust_id); ResultSet rs = ps.executeQuery(); if (rs.next()) { tax_rates = rs.getBigDecimal(1); if (logDML) Log.getLogWriter().info("tax rate is " + tax_rates); if (rs.next()) { throw new TestException ( selectTaxRate + " has more than 1 row " + "in result set for cx_c_id = " + cust_id); } } else { throw new TestException ( selectTaxRate + " does not get single row " + "in result set for cx_c_id = " + cust_id); } rs.close(); tax_amount = tax_rates.multiply(sell_value.subtract(buy_value)); //update //TRADE //set //T_TAX = tax_amount //where //T_ID = trade_id ps = conn.prepareStatement(updateTaxAmount); ps.setBigDecimal(1, tax_amount); ps.setLong(2, trade_id); int count = ps.executeUpdate(); if (logDML) { Log.getLogWriter().info(updateTaxAmount + " updates T_TAX = " + tax_amount + " for T_ID = " + trade_id); } if (count != 1) { throw new TestException(updateTaxAmount + " should updates only 1 row " + "but updated " + count + " row(s)"); } }
Example 13
Source File: RowsAdaptor.java From database with Apache License 2.0 | 4 votes |
private BigDecimal toBigDecimal(ResultSet rs, int col) throws SQLException { BigDecimal val = rs.getBigDecimal(col); return val == null ? null : fixBigDecimal(val); }
Example 14
Source File: TPCEMarketFeed.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
protected void processSelectTrForUpdate(int i, PreparedStatement updateTradePs, PreparedStatement selectTrPs, Timestamp now_dts, PreparedStatement deleteTradeRequestPs, PreparedStatement insertTradeHistoryPs, ArrayList<TradeInfo> tradeRequest) throws SQLException { BigDecimal req_price_quote; long req_trade_id; int req_trade_qty; String req_trade_type; // declare request_list cursor for // select // TR_T_ID, // TR_BID_PRICE, // TR_TT_ID, // TR_QTY // from // TRADE_REQUEST -- GEMFIREXD-PROPERTIES index=i_tr_s_symb \n // where // TR_S_SYMB = symbol[i] and ( // (TR_TT_ID = type_stop_loss and // TR_BID_PRICE >= price_quote[i]) or // (TR_TT_ID = type_limit_sell and // TR_BID_PRICE <= price_quote[i]) or // (TR_TT_ID = type_limit_buy and // TR_BID_PRICE >= price_quote[i]) // ) try { selectTrPs.setString(1, symbol[i]); selectTrPs.setString(2, type_stop_loss); selectTrPs.setBigDecimal(3, price_quote[i]); selectTrPs.setString(4, type_limit_sell); selectTrPs.setBigDecimal(5, price_quote[i]); selectTrPs.setString(6, type_limit_buy); selectTrPs.setBigDecimal(7, price_quote[i]); ResultSet rs = selectTrPs.executeQuery(); while (rs.next()) { req_trade_id = rs.getLong("TR_T_ID"); req_price_quote = rs.getBigDecimal("TR_BID_PRICE"); req_trade_type = rs.getString("TR_TT_ID"); req_trade_qty = rs.getInt("TR_QTY"); //update trade with date and status updateTradeTxn(updateTradePs, now_dts, req_trade_id); //delete current row in trade_request deleteTradeRequestTxn(deleteTradeRequestPs, req_trade_id); //insert into trade history with new status insertTradeHistoryTxn(insertTradeHistoryPs, req_trade_id, now_dts); /* TradeRequestBuffer[rows_sent].symbol = symbol[i] * TradeRequestBuffer[rows_sent].trade_id = req_trade_id * TradeRequestBuffer[rows_sent].price_quote = req_price_quote * TradeRequestBuffer[rows_sent].trade_qty = req_trade_qty * TradeRequestBuffer[rows_sent].trade_type = req_trade_type rows_sent = * rows_sent + 1 fetch from request_list into req_trade_id, req_price_quote, * req_trade_type, req_trade_qty } /* end of cursor fetch loop */ TradeInfo tr = new TradeInfo(); tr.setPriceQuotes(req_price_quote); tr.setSymbol(symbol[i]); tr.setTradeId(req_trade_id); tr.setTradeQty(req_trade_qty); tr.setTradeType(req_trade_type); tradeRequest.add(tr); } } catch (SQLException se) { if (se.getSQLState().equals("X0Z02") && (!TPCETest.isClient || (TPCETest.isClient && TPCETest.useSyncCommit))) { throw new TestException( "Does not expect conflict exception here, as the" + " the txn already hold the lock for the symbol updated in last_trade table," + " there should be no other txn could modify the same row for symbol " + symbol[i] + " in trade request table " + " the stack trace for the conflict exception is: " + TestHelper.getStackTrace(se)); // other dml op on trade_request is insert in trade order txns, and should // not cause conflicts here // for thin client case, (see #48712) there is small window the committed row (insert from tradeorder) does not fully release the lock // TODO may need to use sync-commit connection to see which one has better // perf result; use retry for now. // Actually the issue is most likely caused by batching ops in txn // The last_trade is REPLICATE table, so the update only hold the lock // on that particular node, further operations may cause conflict // so may need to add disable batching on servers to work around this (too many conflicts and retries) for thin client } else throw se; } }
Example 15
Source File: BigDecimalType.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public Object get(ResultSet rs, String name) throws HibernateException, SQLException { return rs.getBigDecimal(name); }
Example 16
Source File: JdbcPOJOPollInputOperator.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Object getTuple(ResultSet result) { Object obj; try { obj = pojoClass.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { store.disconnect(); throw new RuntimeException(ex); } try { for (int i = 0; i < columnDataTypes.size(); i++) { int type = columnDataTypes.get(i); ActiveFieldInfo afi = columnFieldSetters.get(i); switch (type) { case Types.CHAR: case Types.VARCHAR: String strVal = result.getString(i + 1); ((PojoUtils.Setter<Object, String>)afi.setterOrGetter).set(obj, strVal); break; case Types.BOOLEAN: boolean boolVal = result.getBoolean(i + 1); ((PojoUtils.SetterBoolean<Object>)afi.setterOrGetter).set(obj, boolVal); break; case Types.TINYINT: byte byteVal = result.getByte(i + 1); ((PojoUtils.SetterByte<Object>)afi.setterOrGetter).set(obj, byteVal); break; case Types.SMALLINT: short shortVal = result.getShort(i + 1); ((PojoUtils.SetterShort<Object>)afi.setterOrGetter).set(obj, shortVal); break; case Types.INTEGER: int intVal = result.getInt(i + 1); ((PojoUtils.SetterInt<Object>)afi.setterOrGetter).set(obj, intVal); break; case Types.BIGINT: long longVal = result.getLong(i + 1); ((PojoUtils.SetterLong<Object>)afi.setterOrGetter).set(obj, longVal); break; case Types.FLOAT: float floatVal = result.getFloat(i + 1); ((PojoUtils.SetterFloat<Object>)afi.setterOrGetter).set(obj, floatVal); break; case Types.DOUBLE: double doubleVal = result.getDouble(i + 1); ((PojoUtils.SetterDouble<Object>)afi.setterOrGetter).set(obj, doubleVal); break; case Types.DECIMAL: BigDecimal bdVal = result.getBigDecimal(i + 1); ((PojoUtils.Setter<Object, BigDecimal>)afi.setterOrGetter).set(obj, bdVal); break; case Types.TIMESTAMP: Timestamp tsVal = result.getTimestamp(i + 1); ((PojoUtils.Setter<Object, Timestamp>)afi.setterOrGetter).set(obj, tsVal); break; case Types.TIME: Time timeVal = result.getTime(i + 1); ((PojoUtils.Setter<Object, Time>)afi.setterOrGetter).set(obj, timeVal); break; case Types.DATE: Date dateVal = result.getDate(i + 1); ((PojoUtils.Setter<Object, Date>)afi.setterOrGetter).set(obj, dateVal); break; default: throw new RuntimeException("unsupported data type " + type); } } return obj; } catch (SQLException e) { store.disconnect(); throw new RuntimeException("fetching metadata", e); } }
Example 17
Source File: StreamingQuoteDAOModeFull.java From ZStreamingQuote with MIT License | 4 votes |
/** * getOHLCDataByTimeRange - OHLC values between two time * @param instrumentToken * @param prevTime * @param currTime * @return OHLC quote */ @Override public OHLCquote getOHLCDataByTimeRange(String instrumentToken, String prevTime, String currTime){ OHLCquote ohlcMap = null; if (conn != null) { try { Statement stmt = conn.createStatement(); //SQL query OPEN String openSql = "SELECT LastTradedPrice FROM " + quoteTable + " WHERE Time >= '" + prevTime + "' AND Time <= '" + currTime + "' AND InstrumentToken = '" + instrumentToken + "' ORDER BY Time ASC LIMIT 1"; ResultSet openRs = stmt.executeQuery(openSql); openRs.next(); BigDecimal openQuote = openRs.getBigDecimal("LastTradedPrice"); //System.out.println("OPEN: " + openQuote); //SQL query HIGH String highSql = "SELECT MAX(LastTradedPrice) FROM " + quoteTable + " WHERE Time >= '" + prevTime + "' AND Time <= '" + currTime + "' AND InstrumentToken = '" + instrumentToken + "'"; ResultSet highRs = stmt.executeQuery(highSql); highRs.next(); BigDecimal highQuote = highRs.getBigDecimal(1); //System.out.println("HIGH: " + highQuote); //SQL query LOW String lowSql = "SELECT MIN(LastTradedPrice) FROM " + quoteTable + " WHERE Time >= '" + prevTime + "' AND Time <= '" + currTime + "' AND InstrumentToken = '" + instrumentToken + "'"; ResultSet lowRs = stmt.executeQuery(lowSql); lowRs.next(); BigDecimal lowQuote = lowRs.getBigDecimal(1); //System.out.println("LOW: " + lowQuote); //SQL query CLOSE String closeSql = "SELECT LastTradedPrice FROM " + quoteTable + " WHERE Time >= '" + prevTime + "' AND Time <= '" + currTime + "' AND InstrumentToken = '" + instrumentToken + "' ORDER BY Time DESC LIMIT 1"; ResultSet closeRs = stmt.executeQuery(closeSql); closeRs.next(); BigDecimal closeQuote = closeRs.getBigDecimal("LastTradedPrice"); //System.out.println("CLOSE: " + closeQuote); //SQL query VOL String volSql = "SELECT Volume FROM " + quoteTable + " WHERE Time >= '" + prevTime + "' AND Time <= '" + currTime + "' AND InstrumentToken = '" + instrumentToken + "' ORDER BY Time DESC LIMIT 1"; ResultSet volRs = stmt.executeQuery(volSql); volRs.next(); Long volQuote = volRs.getLong(1); //System.out.println("VOL: " + volQuote); ohlcMap = new OHLCquote(openQuote, highQuote, lowQuote, closeQuote, volQuote); stmt.close(); } catch (SQLException e) { ohlcMap = null; System.out.println("StreamingQuoteDAOModeFull.getOHLCDataByTimeRange(): ERROR: SQLException on fetching data from Table, cause: " + e.getMessage()); // e.printStackTrace(); } } else{ ohlcMap = null; System.out.println("StreamingQuoteDAOModeFull.getOHLCDataByTimeRange(): ERROR: DB conn is null !!!"); } return ohlcMap; }
Example 18
Source File: RowsAdaptor.java From database with Apache License 2.0 | 4 votes |
private BigDecimal toBigDecimal(ResultSet rs, String col) throws SQLException { BigDecimal val = rs.getBigDecimal(col); return val == null ? null : fixBigDecimal(val); }
Example 19
Source File: JdbcPOJOInputOperator.java From attic-apex-malhar with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Object getTuple(ResultSet result) { Object obj; try { obj = pojoClass.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { store.disconnect(); throw new RuntimeException(ex); } try { for (int i = 0; i < fieldInfos.size(); i++) { int type = columnDataTypes.get(i); ActiveFieldInfo afi = columnFieldSetters.get(i); switch (type) { case Types.CHAR: case Types.VARCHAR: String strVal = result.getString(i + 1); ((PojoUtils.Setter<Object, String>)afi.setterOrGetter).set(obj, strVal); break; case Types.BOOLEAN: boolean boolVal = result.getBoolean(i + 1); ((PojoUtils.SetterBoolean<Object>)afi.setterOrGetter).set(obj, boolVal); break; case Types.TINYINT: byte byteVal = result.getByte(i + 1); ((PojoUtils.SetterByte<Object>)afi.setterOrGetter).set(obj, byteVal); break; case Types.SMALLINT: short shortVal = result.getShort(i + 1); ((PojoUtils.SetterShort<Object>)afi.setterOrGetter).set(obj, shortVal); break; case Types.INTEGER: int intVal = result.getInt(i + 1); ((PojoUtils.SetterInt<Object>)afi.setterOrGetter).set(obj, intVal); break; case Types.BIGINT: long longVal = result.getLong(i + 1); ((PojoUtils.SetterLong<Object>)afi.setterOrGetter).set(obj, longVal); break; case Types.FLOAT: float floatVal = result.getFloat(i + 1); ((PojoUtils.SetterFloat<Object>)afi.setterOrGetter).set(obj, floatVal); break; case Types.DOUBLE: double doubleVal = result.getDouble(i + 1); ((PojoUtils.SetterDouble<Object>)afi.setterOrGetter).set(obj, doubleVal); break; case Types.DECIMAL: BigDecimal bdVal = result.getBigDecimal(i + 1); ((PojoUtils.Setter<Object, BigDecimal>)afi.setterOrGetter).set(obj, bdVal); break; case Types.TIMESTAMP: Timestamp tsVal = result.getTimestamp(i + 1); ((PojoUtils.Setter<Object, Timestamp>)afi.setterOrGetter).set(obj, tsVal); break; case Types.TIME: Time timeVal = result.getTime(i + 1); ((PojoUtils.Setter<Object, Time>)afi.setterOrGetter).set(obj, timeVal); break; case Types.DATE: Date dateVal = result.getDate(i + 1); ((PojoUtils.Setter<Object, Date>)afi.setterOrGetter).set(obj, dateVal); break; default: handleUnknownDataType(type, obj, afi); break; } } return obj; } catch (SQLException e) { store.disconnect(); throw new RuntimeException("fetching metadata", e); } }
Example 20
Source File: Issue32NumericTest.java From PgBulkInsert with MIT License | 3 votes |
private ArrayList<BigDecimal> getBigDecimals() throws SQLException { ResultSet rs = getAll(); ArrayList<BigDecimal> results = new ArrayList<>(); while (rs.next()) { BigDecimal z = rs.getBigDecimal("bigDecimal"); results.add(z); } return results; }