List of usage examples for java.sql ResultSet getDouble
double getDouble(String columnLabel) throws SQLException;
ResultSet
object as a double
in the Java programming language. From source file:nl.tudelft.stocktrader.derby.DerbyCustomerDAO.java
public List<Holding> getHoldings(String userID) throws DAOException { PreparedStatement selectHoldings = null; try {/*from ww w. j a v a 2 s . co m*/ selectHoldings = sqlConnection.prepareStatement(SQL_SELECT_HOLDINGS); selectHoldings.setString(1, userID); ResultSet rs = selectHoldings.executeQuery(); List<Holding> holdings = new ArrayList<Holding>(); try { while (rs.next()) { Holding holding = new Holding(rs.getInt(1), rs.getDouble(2), rs.getBigDecimal(3), StockTraderUtility.convertToCalendar(rs.getDate(4)), rs.getString(5), rs.getInt(6)); holdings.add(holding); } } finally { try { rs.close(); } catch (SQLException e) { logger.debug("", e); } } return holdings; } catch (SQLException e) { throw new DAOException("", e); } finally { if (selectHoldings != null) { try { selectHoldings.close(); } catch (SQLException e) { logger.debug("", e); } } } }
From source file:com.sfs.dao.ObjectTypeDAOImpl.java
/** * Load object./* ww w.j a v a2 s . c om*/ * * @param rs the rs * * @return the object type bean * * @throws SQLException the SQL exception */ private ObjectTypeBean loadObject(final ResultSet rs) throws SQLException { ObjectTypeBean objectType = new ObjectTypeBean(); // Create item bean and fill with dataset info. objectType.setObjectTypeId(rs.getInt("ObjectTypeId")); objectType.setObject(rs.getString("Object")); objectType.setName(rs.getString("Name")); objectType.setClassName(rs.getString("Class")); objectType.setAbbreviation(rs.getString("Abbreviation")); objectType.setValue(rs.getDouble("Value")); objectType.setSecurity(rs.getString("Security")); objectType.setLdapMapping(1, rs.getString("LdapMapping")); objectType.setLdapMapping(2, rs.getString("SecondLdapMapping")); objectType.setLdapMapping(3, rs.getString("ThirdLdapMapping")); try { objectType.setCreated(rs.getTimestamp("Created")); } catch (SQLException sqe) { dataLogger.info("Could not load Created date: " + sqe.getMessage()); } objectType.setCreatedBy(rs.getString("CreatedBy")); try { objectType.setModified(rs.getTimestamp("Modified")); } catch (SQLException sqe) { dataLogger.info("Could not load Modified date: " + sqe.getMessage()); } objectType.setModifiedBy(rs.getString("ModifiedBy")); if (objectType.getCreatedBy() != null && this.userDAO != null) { try { objectType.setCreatedByUser(this.userDAO.loadCached(objectType.getCreatedBy())); } catch (Exception e) { dataLogger.info("Could not load CreatedBy UserBean for " + "ObjectTypeId = " + objectType.getObjectTypeId()); } } if (objectType.getModifiedBy() != null && this.userDAO != null) { try { objectType.setModifiedByUser(this.userDAO.loadCached(objectType.getModifiedBy())); } catch (Exception e) { dataLogger.info("Could not load ModifiedBy UserBean for " + "ObjectTypeId = " + objectType.getObjectTypeId()); } } return objectType; }
From source file:gsn.http.restapi.RequestHandler.java
private Double getDouble(ResultSet rs, String fieldName) throws SQLException { Double d = rs.getDouble(fieldName); if (rs.wasNull()) return null; //if (o!=null) return rs.getDouble(fieldName); else/*from w w w . j a va2s. co m*/ return d; }
From source file:net.solarnetwork.node.dao.jdbc.test.PreparedStatementCsvReaderTests.java
@Test public void importTable() throws Exception { final String tableName = "SOLARNODE.TEST_CSV_IO"; executeSqlScript("net/solarnetwork/node/dao/jdbc/test/csv-data-01.sql", false); importData(tableName);/* ww w.j a v a2 s .co m*/ final MutableInt row = new MutableInt(0); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); final Calendar utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); jdbcTemplate.query(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { // TODO Auto-generated method stub return con.prepareStatement("select PK,STR,INUM,DNUM,TS from solarnode.test_csv_io order by pk"); } }, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { row.increment(); final int i = row.intValue(); assertEquals("PK " + i, i, rs.getLong(1)); if (i == 2) { assertNull("STR " + i, rs.getString(2)); } else { assertEquals("STR " + i, "s0" + i, rs.getString(2)); } if (i == 3) { assertNull("INUM " + i, rs.getObject(3)); } else { assertEquals("INUM " + i, i, rs.getInt(3)); } if (i == 4) { assertNull("DNUM " + i, rs.getObject(4)); } else { assertEquals("DNUM " + i, i, rs.getDouble(4), 0.01); } if (i == 5) { assertNull("TS " + i, rs.getObject(5)); } else { Timestamp ts = rs.getTimestamp(5, utcCalendar); try { assertEquals("TS " + i, sdf.parse("2016-10-0" + i + "T12:01:02.345Z"), ts); } catch (ParseException e) { // should not get here } } } }); assertEquals("Imported count", 5, row.intValue()); }
From source file:ui.Analyze.java
private Number getRugi(LocalDate l2) throws SQLException { double dou = 0; java.sql.PreparedStatement p = d.getPS("select sum(sat*jum)as oke from memasok where tgl=?"); p.setDate(1, Date.valueOf(l2)); java.sql.ResultSet r = p.executeQuery(); if (r.next()) dou = r.getDouble("oke"); r.close();// w w w .j av a 2 s. c o m p.close(); return dou; }
From source file:StocksTable5.java
public int retrieveData(final java.util.Date date) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date);// www .j a va 2 s . c om int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); int year = calendar.get(Calendar.YEAR); final String query = "SELECT data.symbol, symbols.name, " + "data.last, data.open, data.change, data.changeproc, " + "data.volume FROM DATA INNER JOIN SYMBOLS " + "ON DATA.symbol = SYMBOLS.symbol WHERE " + "month(data.date1)=" + month + " AND day(data.date1)=" + day + " AND year(data.date1)=" + year; Thread runner = new Thread() { public void run() { try { // Load the JDBC-ODBC bridge driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:Market", "admin", ""); Statement stmt = conn.createStatement(); ResultSet results = stmt.executeQuery(query); boolean hasData = false; while (results.next()) { if (!hasData) { m_vector.removeAllElements(); hasData = true; } String symbol = results.getString(1); String name = results.getString(2); double last = results.getDouble(3); double open = results.getDouble(4); double change = results.getDouble(5); double changePr = results.getDouble(6); long volume = results.getLong(7); m_vector.addElement(new StockData(symbol, name, last, open, change, changePr, volume)); } results.close(); stmt.close(); conn.close(); if (!hasData) // We've got nothing m_result = 1; } catch (Exception e) { e.printStackTrace(); System.err.println("Load data error: " + e.toString()); m_result = -1; } m_date = date; Collections.sort(m_vector, new StockComparator(m_sortCol, m_sortAsc)); m_result = 0; } }; runner.start(); return m_result; }
From source file:dk.netarkivet.harvester.datamodel.RunningJobsInfoDBDAO.java
/** * Get a frontierReportLine from the resultSet. * @param rs the resultset with data from table frontierReportMonitor * @return a frontierReportLine from the resultSet. * @throws SQLException If unable to get data from resultSet *//*from www . ja v a 2s . c om*/ private FrontierReportLine getLine(ResultSet rs) throws SQLException { FrontierReportLine line = new FrontierReportLine(); line.setAverageCost(rs.getDouble(FR_COLUMN.averageCost.rank())); line.setCurrentSize(rs.getLong(FR_COLUMN.currentSize.rank())); line.setDomainName(rs.getString(FR_COLUMN.domainName.rank())); line.setErrorCount(rs.getLong(FR_COLUMN.errorCount.rank())); line.setLastCost(rs.getDouble(FR_COLUMN.lastCost.rank())); line.setLastDequeueTime(rs.getString(FR_COLUMN.lastDequeueTime.rank())); line.setLastPeekUri(rs.getString(FR_COLUMN.lastPeekUri.rank())); line.setLastQueuedUri(rs.getString(FR_COLUMN.lastQueuedUri.rank())); line.setSessionBalance(rs.getLong(FR_COLUMN.sessionBalance.rank())); line.setTotalBudget(rs.getLong(FR_COLUMN.totalBudget.rank())); line.setTotalEnqueues(rs.getLong(FR_COLUMN.totalEnqueues.rank())); line.setTotalSpend(rs.getLong(FR_COLUMN.totalSpend.rank())); line.setWakeTime(rs.getString(FR_COLUMN.wakeTime.rank())); return line; }
From source file:de.static_interface.reallifeplugin.module.contract.database.table.ContractUserOptionsTable.java
@Override public ContractUserOptionsRow[] deserialize(ResultSet rs) throws SQLException { int rowcount = 0; if (rs.last()) { rowcount = rs.getRow();//w w w .java 2 s. com rs.beforeFirst(); } ContractUserOptionsRow[] rows = new ContractUserOptionsRow[rowcount]; int i = 0; while (rs.next()) { ContractUserOptionsRow row = new ContractUserOptionsRow(); if (hasColumn(rs, "id")) { row.id = rs.getInt("id"); } if (hasColumn(rs, "user_id")) { row.userId = rs.getInt("userId"); } if (hasColumn(rs, "contract_id")) { row.contractId = rs.getInt("contract_id"); } if (hasColumn(rs, "isCreator")) { row.isCreator = rs.getBoolean("isCreator"); } if (hasColumn(rs, "money")) { row.money = rs.getDouble("money"); if (rs.wasNull()) { row.money = null; } } rows[i] = row; i++; } return rows; }
From source file:com.alibaba.otter.node.etl.common.db.utils.SqlUtils.java
/** * Retrieve a JDBC column value from a ResultSet, using the specified value * type./*from ww w .j a va 2s . c om*/ * <p> * Uses the specifically typed ResultSet accessor methods, falling back to * {@link #getResultSetValue(java.sql.ResultSet, int)} for unknown types. * <p> * Note that the returned value may not be assignable to the specified * required type, in case of an unknown type. Calling code needs to deal * with this case appropriately, e.g. throwing a corresponding exception. * * @param rs is the ResultSet holding the data * @param index is the column index * @param requiredType the required value type (may be <code>null</code>) * @return the value object * @throws SQLException if thrown by the JDBC API */ private static String getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } Object value = null; boolean wasNullCheck = false; // Explicitly extract typed value, as far as possible. if (String.class.equals(requiredType)) { value = rs.getString(index); } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) { value = Boolean.valueOf(rs.getBoolean(index)); wasNullCheck = true; } else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) { value = new Byte(rs.getByte(index)); wasNullCheck = true; } else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) { value = new Short(rs.getShort(index)); wasNullCheck = true; } else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) { value = new Long(rs.getLong(index)); wasNullCheck = true; } else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) { value = rs.getBigDecimal(index); wasNullCheck = true; } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) { value = new Float(rs.getFloat(index)); wasNullCheck = true; } else if (double.class.equals(requiredType) || Double.class.equals(requiredType) || Number.class.equals(requiredType)) { value = new Double(rs.getDouble(index)); wasNullCheck = true; } else if (java.sql.Time.class.equals(requiredType)) { // try { // value = rs.getTime(index); // } catch (SQLException e) { value = rs.getString(index);// ?string0000Time // if (value == null && !rs.wasNull()) { // value = "00:00:00"; // // mysqlzeroDateTimeBehavior=convertToNull0null // } // } } else if (java.sql.Timestamp.class.equals(requiredType) || java.sql.Date.class.equals(requiredType)) { // try { // value = convertTimestamp(rs.getTimestamp(index)); // } catch (SQLException e) { // ?string0000-00-00 00:00:00Timestamp value = rs.getString(index); // if (value == null && !rs.wasNull()) { // value = "0000:00:00 00:00:00"; // // mysqlzeroDateTimeBehavior=convertToNull0null // } // } } else if (BigDecimal.class.equals(requiredType)) { value = rs.getBigDecimal(index); } else if (BigInteger.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 if (byte[].class.equals(requiredType)) { try { byte[] bytes = rs.getBytes(index); if (bytes == null) { value = null; } else { value = new String(bytes, "ISO-8859-1");// binaryiso-8859-1 } } catch (UnsupportedEncodingException e) { throw new SQLException(e); } } else { // Some unknown type desired -> rely on getObject. value = getResultSetValue(rs, index); } // Perform was-null check if demanded (for results that the // JDBC driver returns as primitives). if (wasNullCheck && (value != null) && rs.wasNull()) { value = null; } return (value == null) ? null : convertUtilsBean.convert(value); }
From source file:ui.Analyze.java
private Component buatPermintaan(LocalDate l) throws SQLException { org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset(); java.sql.PreparedStatement p = d.getPS( "select detjual.brg,sum(detjual.jum)as qty from jual inner join detjual where jual.tgl>=? and " + "jual.tgl<? group by detjual.brg"); p.setDate(1, Date.valueOf(l)); p.setDate(2, Date.valueOf(l.plusMonths(1))); java.sql.ResultSet r = p.executeQuery(); while (r.next()) data.setValue(getNamaBrg(r.getString("brg")), r.getDouble("qty")); r.close();//from w ww . j av a 2s. c o m p.close(); return new org.jfree.chart.ChartPanel(ChartFactory.createPieChart("PERMINTAAN", data, true, true, false)); }