public void deleteInsertTodaysStockList(ErrorObject error, DatabaseClass db) { Connection conn = null; PreparedStatement pst = null; PreparedStatement pst2 = null; String delete = "delete from stock_information " + "where information_date = ?"; String sql = "insert into stock_information (information_date, " + "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) " + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; try { conn = DriverManager.getConnection(db.getUrl(), db.getUsr(), db.getPwd()); conn.setAutoCommit(false); if (this.size() != 0) { StockInformation si = this.get(0); pst2 = conn.prepareStatement(delete); pst2.setDate(1, new java.sql.Date(si.getInformationDate().getTime())); pst2.executeUpdate(); } pst = conn.prepareStatement(sql); for (int i = 0; i < this.size(); i++) { StockInformation s = this.get(i); pst.setDate(1, new java.sql.Date(s.getInformationDate().getTime())); pst.setString(2, s.getTicker()); pst.setString(3, s.getName()); pst.setString(4, s.getIsin()); pst.setString(5, s.getCurrency()); pst.setString(6, s.getMarketplace()); pst.setString(7, s.getListname()); pst.setDouble(8, s.getAveragePrice().doubleValue()); pst.setDouble(9, s.getOpenPrice().doubleValue()); pst.setDouble(10, s.getHighPrice().doubleValue()); pst.setDouble(11, s.getLowPrice().doubleValue()); pst.setDouble(12, s.getLastClosePrice().doubleValue()); pst.setDouble(13, s.getLastPrice().doubleValue()); pst.setDouble(14, s.getPriceChangePercentage().doubleValue()); pst.setDouble(15, s.getBestBid().doubleValue()); pst.setDouble(16, s.getBestAsk().doubleValue()); pst.setInt(17, s.getTrades().intValue()); pst.setInt(18, s.getVolume().intValue()); pst.setDouble(19, s.getTurnover().doubleValue()); pst.executeUpdate(); } 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) { } } } }