List of usage examples for java.sql ResultSet getBigDecimal
BigDecimal getBigDecimal(String columnLabel) throws SQLException;
ResultSet
object as a java.math.BigDecimal
with full precision. From source file:org.kuali.kfs.gl.batch.dataaccess.impl.LedgerPreparedStatementCachingDaoJdbc.java
public AccountBalance getAccountBalance(final Transaction t) { return new RetrievingJdbcWrapper<AccountBalance>() { @Override// w w w . j a v a 2 s .c o m protected void populateStatement(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setInt(1, t.getUniversityFiscalYear()); preparedStatement.setString(2, t.getChartOfAccountsCode()); preparedStatement.setString(3, t.getAccountNumber()); preparedStatement.setString(4, t.getSubAccountNumber()); preparedStatement.setString(5, t.getFinancialObjectCode()); preparedStatement.setString(6, t.getFinancialSubObjectCode()); } @Override protected AccountBalance extractResult(ResultSet resultSet) throws SQLException { AccountBalance accountBalance = new AccountBalance(); accountBalance.setUniversityFiscalYear(t.getUniversityFiscalYear()); accountBalance.setChartOfAccountsCode(t.getChartOfAccountsCode()); accountBalance.setAccountNumber(t.getAccountNumber()); accountBalance.setSubAccountNumber(t.getSubAccountNumber()); accountBalance.setObjectCode(t.getFinancialObjectCode()); accountBalance.setSubObjectCode(t.getFinancialSubObjectCode()); accountBalance.setCurrentBudgetLineBalanceAmount(new KualiDecimal(resultSet.getBigDecimal(1))); accountBalance.setAccountLineActualsBalanceAmount(new KualiDecimal(resultSet.getBigDecimal(2))); accountBalance.setAccountLineEncumbranceBalanceAmount(new KualiDecimal(resultSet.getBigDecimal(3))); return accountBalance; } }.get(AccountBalance.class); }
From source file:org.kuali.kfs.gl.batch.dataaccess.impl.LedgerPreparedStatementCachingDaoJdbc.java
public Balance getBalance(final Transaction t) { return new RetrievingJdbcWrapper<Balance>() { @Override/*from w w w. ja v a2s . c om*/ protected void populateStatement(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setInt(1, t.getUniversityFiscalYear()); preparedStatement.setString(2, t.getChartOfAccountsCode()); preparedStatement.setString(3, t.getAccountNumber()); preparedStatement.setString(4, t.getSubAccountNumber()); preparedStatement.setString(5, t.getFinancialObjectCode()); preparedStatement.setString(6, t.getFinancialSubObjectCode()); preparedStatement.setString(7, t.getFinancialBalanceTypeCode()); preparedStatement.setString(8, t.getFinancialObjectTypeCode()); } @Override protected Balance extractResult(ResultSet resultSet) throws SQLException { Balance balance = new Balance(); balance.setUniversityFiscalYear(t.getUniversityFiscalYear()); balance.setChartOfAccountsCode(t.getChartOfAccountsCode()); balance.setAccountNumber(t.getAccountNumber()); balance.setSubAccountNumber(t.getSubAccountNumber()); balance.setObjectCode(t.getFinancialObjectCode()); balance.setSubObjectCode(t.getFinancialSubObjectCode()); balance.setBalanceTypeCode(t.getFinancialBalanceTypeCode()); balance.setObjectTypeCode(t.getFinancialObjectTypeCode()); balance.setAccountLineAnnualBalanceAmount(new KualiDecimal(resultSet.getBigDecimal(1))); balance.setBeginningBalanceLineAmount(new KualiDecimal(resultSet.getBigDecimal(2))); balance.setContractsGrantsBeginningBalanceAmount(new KualiDecimal(resultSet.getBigDecimal(3))); balance.setMonth1Amount(new KualiDecimal(resultSet.getBigDecimal(4))); balance.setMonth2Amount(new KualiDecimal(resultSet.getBigDecimal(5))); balance.setMonth3Amount(new KualiDecimal(resultSet.getBigDecimal(6))); balance.setMonth4Amount(new KualiDecimal(resultSet.getBigDecimal(7))); balance.setMonth5Amount(new KualiDecimal(resultSet.getBigDecimal(8))); balance.setMonth6Amount(new KualiDecimal(resultSet.getBigDecimal(9))); balance.setMonth7Amount(new KualiDecimal(resultSet.getBigDecimal(10))); balance.setMonth8Amount(new KualiDecimal(resultSet.getBigDecimal(11))); balance.setMonth9Amount(new KualiDecimal(resultSet.getBigDecimal(12))); balance.setMonth10Amount(new KualiDecimal(resultSet.getBigDecimal(13))); balance.setMonth11Amount(new KualiDecimal(resultSet.getBigDecimal(14))); balance.setMonth12Amount(new KualiDecimal(resultSet.getBigDecimal(15))); balance.setMonth13Amount(new KualiDecimal(resultSet.getBigDecimal(16))); return balance; } }.get(Balance.class); }
From source file:com.wso2telco.dep.reportingservice.dao.TaxDAO.java
/** * Gets the taxes for tax list.//ww w .j a v a 2 s . c o m * * @param taxList the tax list * @return the taxes for tax list * @throws Exception the exception */ public List<Tax> getTaxesForTaxList(List<String> taxList) throws Exception { Connection connection = null; Statement st = null; ResultSet results = null; List<Tax> taxes = new ArrayList<Tax>(); if (taxList == null || taxList.isEmpty()) { return taxes; } // CSV format surrounded by single quote String taxListStr = taxList.toString().replace("[", "'").replace("]", "'").replace(", ", "','"); String sql = "SELECT type,effective_from,effective_to,value FROM " + ReportingTable.TAX + " WHERE type IN (" + taxListStr + ")"; try { connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); st = connection.createStatement(); log.debug("In getTaxesForTaxList"); log.debug("SQL (PS) ---> " + st.toString()); results = st.executeQuery(sql); while (results.next()) { Tax tax = new Tax(); tax.setType(results.getString("type")); tax.setEffective_from(results.getDate("effective_from")); tax.setEffective_to(results.getDate("effective_to")); tax.setValue(results.getBigDecimal("value")); taxes.add(tax); } st.close(); } catch (SQLException e) { log.error("SQL Error in getTaxesForTaxList"); log.error(e.getStackTrace()); handleException("Error occurred while getting Taxes for Tax List", e); } finally { DbUtils.closeAllConnections(null, connection, results); } return taxes; }
From source file:org.jtotus.database.LocalJDBC.java
public BigDecimal fetchData(String tableName, DateTime date, String column) { BigDecimal retValue = null;//from www. j a v a 2 s . co m PreparedStatement pstm = null; Connection connection = null; ResultSet results = null; try { connection = getConnection(); String statement = "SELECT " + column + " FROM " + this.normTableName(tableName) + " WHERE DATE=?"; this.createTable(connection, this.normTableName(tableName)); pstm = connection.prepareStatement(statement); java.sql.Date sqlDate = new java.sql.Date(date.getMillis()); pstm.setDate(1, sqlDate); if (debug) { System.out.printf("Fetching:'%s' from'%s' Time" + date.toDate() + " Stm:%s\n", column, tableName, statement); } results = pstm.executeQuery(); // System.out.printf("Results:%d :%d :%s (%d)\n",results.getType(), results.findColumn(column), results.getMetaData().getColumnLabel(1),java.sql.Types.DOUBLE); if (results.next()) { retValue = results.getBigDecimal(column); } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + date.toDate() + "\n", column, tableName); // Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (results != null) { results.close(); results = null; } if (pstm != null) { pstm.close(); pstm = null; } if (connection != null) { connection.close(); connection = null; } } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return retValue; }
From source file:com.wso2telco.dep.reportingservice.dao.TaxDAO.java
/** * Gets the taxes for subscription./* w ww . j ava 2 s .co m*/ * * @param applicationId the application id * @param apiId the api id * @return the taxes for subscription * @throws Exception the exception */ public List<Tax> getTaxesForSubscription(int applicationId, int apiId) throws Exception { Connection connection = null; PreparedStatement ps = null; ResultSet results = null; String sql = "SELECT type,effective_from,effective_to,value FROM " + ReportingTable.TAX + ", " + ReportingTable.SUBSCRIPTION_TAX + "WHERE subscription_tax.application_id=? AND subscription_tax.api_id=? AND tax.type=subscription_tax.tax_type "; List<Tax> taxes = new ArrayList<Tax>(); try { connection = DbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB); ps = connection.prepareStatement(sql); log.debug("getTaxesForSubscription for applicationId---> " + applicationId + " apiId--> " + apiId); ps.setInt(1, applicationId); ps.setInt(2, apiId); log.debug("SQL (PS) ---> " + ps.toString()); results = ps.executeQuery(); while (results.next()) { Tax tax = new Tax(); tax.setType(results.getString("type")); tax.setEffective_from(results.getDate("effective_from")); tax.setEffective_to(results.getDate("effective_to")); tax.setValue(results.getBigDecimal("value")); taxes.add(tax); } } catch (SQLException e) { log.error("SQL Error in getTaxesForSubscription"); log.error(e.getStackTrace()); handleException("Error occurred while getting Taxes for Subscription", e); } finally { DbUtils.closeAllConnections(ps, connection, results); } return taxes; }
From source file:org.dbist.dml.impl.DmlJdbc.java
private static Object toRequiredType(ResultSet rs, int index, Class<?> requiredType) throws SQLException { if (requiredType == null) return rs.getObject(index); if (ValueUtils.isPrimitive(requiredType)) { if (requiredType.equals(String.class)) return rs.getString(index); if (requiredType.equals(Character.class) || requiredType.equals(char.class)) { String str = rs.getString(index); if (str == null || str.length() == 0) return null; return str.charAt(0); }/*from w w w . j a v a 2s . co m*/ if (requiredType.equals(BigDecimal.class)) return rs.getBigDecimal(index); if (requiredType.equals(Date.class)) return rs.getTimestamp(index); if (requiredType.equals(Double.class) || requiredType.equals(double.class)) return rs.getDouble(index); if (requiredType.equals(Float.class) || requiredType.equals(float.class)) return rs.getFloat(index); if (requiredType.equals(Long.class) || requiredType.equals(long.class)) return rs.getLong(index); if (requiredType.equals(Integer.class) || requiredType.equals(int.class)) return rs.getInt(index); if (requiredType.equals(Boolean.class) || requiredType.equals(boolean.class)) return rs.getBoolean(index); if (requiredType.equals(Byte[].class) || requiredType.equals(byte[].class)) return rs.getBytes(index); if (requiredType.equals(Byte.class) || requiredType.equals(byte.class)) return rs.getByte(index); } return rs.getObject(index); }
From source file:org.snaker.engine.access.jdbc.JdbcHelper.java
/** * ?ResultSet?index?requiredType?/*from w w w . ja v a 2s. co m*/ * @param rs * @param index * @param requiredType * @return * @throws SQLException */ public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } Object value = null; boolean wasNullCheck = false; if (String.class.equals(requiredType)) { value = rs.getString(index); } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) { value = rs.getBoolean(index); wasNullCheck = true; } else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) { value = rs.getByte(index); wasNullCheck = true; } else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) { value = rs.getShort(index); wasNullCheck = true; } else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) { value = rs.getInt(index); wasNullCheck = true; } else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) { value = rs.getLong(index); wasNullCheck = true; } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) { value = rs.getFloat(index); wasNullCheck = true; } else if (double.class.equals(requiredType) || Double.class.equals(requiredType) || Number.class.equals(requiredType)) { value = rs.getDouble(index); wasNullCheck = true; } else if (byte[].class.equals(requiredType)) { value = rs.getBytes(index); } else if (java.sql.Date.class.equals(requiredType)) { value = rs.getDate(index); } else if (java.sql.Time.class.equals(requiredType)) { value = rs.getTime(index); } else if (java.sql.Timestamp.class.equals(requiredType) || java.util.Date.class.equals(requiredType)) { value = rs.getTimestamp(index); } else if (BigDecimal.class.equals(requiredType)) { value = rs.getBigDecimal(index); } else if (Blob.class.equals(requiredType)) { value = rs.getBlob(index); } else if (Clob.class.equals(requiredType)) { value = rs.getClob(index); } else { value = getResultSetValue(rs, index); } if (wasNullCheck && value != null && rs.wasNull()) { value = null; } return value; }
From source file:com.nextep.designer.sqlgen.db2.impl.DB2Capturer.java
@Override public Collection<ISequence> getSequences(ICaptureContext context, IProgressMonitor monitor) { monitor.subTask("Retrieving sequences..."); Collection<ISequence> sequences = new ArrayList<ISequence>(); Statement stmt = null;/*from www. j a v a2 s . c om*/ ResultSet rset = null; try { stmt = ((Connection) context.getConnectionObject()).createStatement(); rset = stmt.executeQuery("SELECT seqname, remarks, start, minvalue, maxvalue, increment, cache, " //$NON-NLS-1$ + "DECODE(cycle,'Y',1,0) is_cycle, DECODE(order,'Y',1,0) is_order " //$NON-NLS-1$ + "FROM syscat.sequences WHERE seqschema = '" + context.getSchema() + "' AND seqtype <> 'A'"); //$NON-NLS-1$ //$NON-NLS-2$ CaptureHelper.updateMonitor(monitor, getCounter(), 1, 1); while (rset.next()) { final String seqName = rset.getString("seqname"); //$NON-NLS-1$ final String seqDesc = rset.getString("remarks"); //$NON-NLS-1$ final BigDecimal seqStart = rset.getBigDecimal("start"); //$NON-NLS-1$ final BigDecimal seqMinvalue = rset.getBigDecimal("minvalue"); //$NON-NLS-1$ final BigDecimal seqMaxvalue = rset.getBigDecimal("maxvalue"); //$NON-NLS-1$ /* * FIXME [BGA]: The increment value in DB2 dictionary tables is stored as a * DECIMAL(31,0), like the start, min and max values of the sequences. We should * check if it poses a problem with the mapping with a "Long" in the neXtep model * and a "BIGINT" in the neXtep repository. */ final long seqIncrement = rset.getLong("increment"); //$NON-NLS-1$ final int seqCacheSize = rset.getInt("cache"); //$NON-NLS-1$ final boolean isCycle = rset.getBoolean("is_cycle"); //$NON-NLS-1$ final boolean isOrder = rset.getBoolean("is_order"); //$NON-NLS-1$ if (seqName != null && !"".equals(seqName.trim())) { //$NON-NLS-1$ if (LOGGER.isDebugEnabled()) { String logPrefix = "[" + seqName + "]"; //$NON-NLS-1$ //$NON-NLS-2$ LOGGER.debug("= " + logPrefix + " Sequence Metadata ="); //$NON-NLS-1$ //$NON-NLS-2$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.START] " + seqStart); //$NON-NLS-1$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.MINVALUE] " + seqMinvalue); //$NON-NLS-1$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.MAXVALUE] " + seqMaxvalue); //$NON-NLS-1$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.INCREMENT] " + seqIncrement); //$NON-NLS-1$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.CACHE] " + seqCacheSize); //$NON-NLS-1$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.CYCLE] " //$NON-NLS-1$ + (isCycle ? "Y" : "N")); //$NON-NLS-1$ //$NON-NLS-2$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.ORDER] " //$NON-NLS-1$ + (isOrder ? "Y" : "N")); //$NON-NLS-1$ //$NON-NLS-2$ LOGGER.debug(logPrefix + "[SYSCAT.SEQUENCES.REMARKS] " + seqDesc); //$NON-NLS-1$ } if (seqStart != null && seqMinvalue != null && seqMaxvalue != null) { IVersionable<ISequence> v = VersionableFactory.createVersionable(ISequence.class); ISequence sequence = v.getVersionnedObject().getModel(); sequence.setName(seqName); sequence.setDescription(seqDesc); sequence.setStart(seqStart); sequence.setMinValue(seqMinvalue); sequence.setMaxValue(seqMaxvalue); sequence.setIncrement(seqIncrement); sequence.setCached(seqCacheSize > 0); sequence.setCacheSize(seqCacheSize); sequence.setCycle(isCycle); sequence.setOrdered(isOrder); sequences.add(sequence); CaptureHelper.updateMonitor(monitor, getCounter(), 5, 1); } else { LOGGER.warn("Sequence [" + seqName + "] has been ignored during import because one of its " + "start, minimum or maximum values could not be fetched " + "from database"); } } } } catch (SQLException sqle) { LOGGER.error("Unable to fetch synonyms from DB2 server: " + sqle.getMessage(), sqle); } finally { CaptureHelper.safeClose(rset, stmt); } return sequences; }
From source file:org.jtotus.database.LocalJDBC.java
public HashMap<String, Double> fetchPeriodAsMap(String tableName, DateTime startDate, DateTime endDate) { HashMap<String, Double> retMap = new HashMap<String, Double>(); BigDecimal retValue = null;//from w w w. ja v a 2 s . c o m PreparedStatement pstm = null; java.sql.Date retDate = null; ResultSet results = null; Connection connection = null; try { String query = "SELECT CLOSE, DATE FROM " + this.normTableName(tableName) + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC"; // this.createTable(connection, this.normTableName(tableName)); connection = this.getConnection(); pstm = connection.prepareStatement(query); java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis()); pstm.setDate(1, startSqlDate); java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis()); pstm.setDate(2, endSqlDate); System.out.printf("fetchPeriod : %s : %s\n", startSqlDate, endSqlDate); DateIterator iter = new DateIterator(startDate, endDate); results = pstm.executeQuery(); DateTime dateCheck; while (results.next()) { retValue = results.getBigDecimal(1); retDate = results.getDate(2); if (retValue == null || retDate == null) { System.err.println("Database is corrupted!"); System.exit(-1); } if (iter.hasNext()) { dateCheck = iter.nextInCalendar(); DateTime compCal = new DateTime(retDate.getTime()); if (debug) { if (retValue != null) { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%f date:%s\n", "Closing Price", tableName, retValue.doubleValue(), retDate.toString()); } else { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%s date:%s\n", "Closing Price", tableName, "is null", retDate.toString()); } } if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth() && compCal.getMonthOfYear() == dateCheck.getMonthOfYear() && compCal.getYear() == dateCheck.getYear()) { retMap.put(formatter.print(compCal), retValue.doubleValue()); continue; } while (((compCal.getDayOfMonth() != dateCheck.getDayOfMonth()) || (compCal.getMonthOfYear() != dateCheck.getMonthOfYear()) || (compCal.getYear() != dateCheck.getYear())) && dateCheck.isBefore(compCal)) { if (fetcher != null) { BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, "CLOSE"); if (failOverValue != null) { retMap.put(formatter.print(dateCheck), retValue.doubleValue()); } if (iter.hasNext()) { System.err.printf("Warning : Miss matching dates for: %s - %s\n", retDate.toString(), dateCheck.toString()); dateCheck = iter.nextInCalendar(); continue; } } else { System.err.printf("Fatal missing fetcher : Miss matching dates: %s - %s\n", retDate.toString(), dateCheck.toString()); return null; } } } } while (iter.hasNext()) { retValue = getFetcher().fetchData(tableName, iter.nextInCalendar(), "CLOSE"); if (retValue != null) { retMap.put(formatter.print(iter.getCurrentAsCalendar()), retValue.doubleValue()); } } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n", "Cosing Price", tableName); // ex.printStackTrace(); // SQLException xp = null; // while((xp = ex.getNextException()) != null) { // xp.printStackTrace(); // } } finally { try { if (results != null) results.close(); if (pstm != null) pstm.close(); if (connection != null) connection.close(); // System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections()); // mainPool.dispose(); } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return retMap; }
From source file:org.plasma.sdo.access.provider.jdbc.JDBCDataConverter.java
public Object fromJDBCDataType(ResultSet rs, int columnIndex, int sourceType, PlasmaProperty targetProperty) throws SQLException { Object result = null;// w w w .j a v a2 s. c o m if (targetProperty.getType().isDataType()) { DataType targetDataType = DataType.valueOf(targetProperty.getType().getName()); switch (targetDataType) { case String: case URI: case Month: case MonthDay: case Day: case Time: case Year: case YearMonth: case YearMonthDay: case Duration: result = rs.getString(columnIndex); break; case Date: java.sql.Timestamp ts = rs.getTimestamp(columnIndex); if (ts != null) result = new java.util.Date(ts.getTime()); break; case DateTime: ts = rs.getTimestamp(columnIndex); if (ts != null) result = new java.util.Date(ts.getTime()); break; case Decimal: result = rs.getBigDecimal(columnIndex); break; case Bytes: result = rs.getBytes(columnIndex); break; case Byte: result = rs.getByte(columnIndex); break; case Boolean: result = rs.getBoolean(columnIndex); break; case Character: result = rs.getInt(columnIndex); break; case Double: result = rs.getDouble(columnIndex); break; case Float: result = rs.getFloat(columnIndex); break; case Int: result = rs.getInt(columnIndex); break; case Integer: result = new BigInteger(rs.getString(columnIndex)); break; case Long: result = rs.getLong(columnIndex); break; case Short: result = rs.getShort(columnIndex); break; case Strings: String value = rs.getString(columnIndex); String[] values = value.split("\\s"); List<String> list = new ArrayList<String>(values.length); for (int i = 0; i < values.length; i++) list.add(values[i]); // what no Java 5 sugar for this ?? result = list; break; case Object: default: result = rs.getObject(columnIndex); break; } } else { // FIXME: or get the opposite containing type // of the property and get its pri-key(s) result = rs.getObject(columnIndex); } return result; }