public void retrieveDateList(ErrorObject error, DatabaseClass db) { Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; String sql = "select distinct information_date " + "from stock_information order by information_date "; this.clear(); try { conn = DriverManager.getConnection(db.getUrl(), db.getUsr(), db.getPwd()); conn.setAutoCommit(false); pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { StockInformation si = new StockInformation(); si.setInformationDate(rs.getDate(1)); this.add(si); } rs.close(); conn.commit(); pst.close(); conn.close(); } catch (SQLException e) { System.out.println("DB Error: " + e.getMessage()); error.setError(true); error.setMessage(e.getMessage()); if (conn != null) { try { conn.close(); } catch (SQLException e2) { } } } }
public void retrieveStockInformationList(ErrorObject error, DatabaseClass db, Date start) { Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; String sql = "select id, ticker, name, isin, currency, " + "marketplace, listname, average_price, " + "open_price, high_price, low_price, " + "last_close_price, last_price, " + "price_change_percentage, best_bid, best_ask, " + "trades, volume, turnover " + "from stock_information " + "where information_date = ?"; this.clear(); try { conn = DriverManager.getConnection(db.getUrl(), db.getUsr(), db.getPwd()); conn.setAutoCommit(false); pst = conn.prepareStatement(sql); long date = start.getTime(); java.sql.Date sqlDate = new java.sql.Date(date); pst.setDate(1, sqlDate); rs = pst.executeQuery(); while (rs.next()) { StockInformation si = new StockInformation(); si.setId(new Integer(rs.getInt(1))); si.setInformationDate(start); si.setTicker(rs.getString(2)); si.setName(rs.getString(3)); si.setIsin(rs.getString(4)); si.setCurrency(rs.getString(5)); si.setMarketplace(rs.getString(6)); si.setListname(rs.getString(7)); si.setAveragePrice(new Double(rs.getDouble(8))); si.setOpenPrice(new Double(rs.getDouble(9))); si.setHighPrice(new Double(rs.getDouble(10))); si.setLowPrice(new Double(rs.getDouble(11))); si.setLastClosePrice(new Double(rs.getDouble(12))); si.setLastPrice(new Double(rs.getDouble(13))); si.setPriceChangePercentage(new Double(rs.getDouble(14))); si.setBestBid(new Double(rs.getDouble(15))); si.setBestAsk(new Double(rs.getDouble(16))); si.setTrades(new Integer(rs.getInt(17))); si.setVolume(new Integer(rs.getInt(18))); si.setTurnover(new Double(rs.getDouble(19))); this.add(si); } rs.close(); conn.commit(); pst.close(); conn.close(); } catch (SQLException e) { System.out.println("DB Error: " + e.getMessage()); error.setError(true); error.setMessage(e.getMessage()); if (conn != null) { try { conn.close(); } catch (SQLException e2) { } } } }