Ejemplo n.º 1
0
 private void readDataBase() {
   try {
     logger.traceINFO("Initializing database...");
     Class.forName("com.mysql.jdbc.Driver");
     connect =
         DriverManager.getConnection("jdbc:mysql://localhost/marketdata?" + "user=root&password=");
   } catch (Exception e) {
     logger.traceERROR(e);
     System.exit(0);
   }
 }
Ejemplo n.º 2
0
  public void close() {
    try {
      if (resultSet != null) {
        resultSet.close();
      }

      if (statement != null) {
        statement.close();
      }

      if (connect != null) {
        connect.close();
      }
    } catch (Exception e) {
      logger.traceERROR(e);
    }
  }
Ejemplo n.º 3
0
 public void insertMarketData(String symbol, String price) {
   String query =
       "INSERT INTO `marketdata`.`market_data` (`ID`, `SYMBOL`, `PRICE`, `TIMESTAMP`) VALUES (NULL, '"
           + symbol
           + "', '"
           + price
           + "', CURRENT_TIMESTAMP);";
   logger.traceINFO("Inserting ( " + symbol + ", " + price + " )");
   try {
     connect.createStatement().execute(query);
   } catch (CommunicationsException e) {
     readDataBase();
     insertMarketData(symbol, price);
   } catch (Exception e) {
     logger.traceERROR(e);
   }
 }