Beispiel #1
0
 /**
  * Drop the listofsymbols and recreate - this is a one-off method, I was adding SP symbols in
  * sets, but this table was repeatedly deleted in the process.
  *
  * @see createDatabase
  */
 public static void updateListOfSymbols(String[] symbolArray) throws Exception {
   Connection conn = initialize();
   Statement stat = conn.createStatement();
   try {
     stat.executeUpdate("DROP TABLE IF EXISTS " + "listofsymbols" + ";");
     stat.executeUpdate(
         "CREATE TABLE IF NOT EXISTS " + "listofsymbols" + " (" + "'symbolname'" + ");");
   } catch (Exception e) {
     System.out.println("failed stat.executeUpdate");
     System.out.println(e.getMessage());
   }
   for (int i = 0; i < symbolArray.length; i++) {
     stat.executeUpdate("INSERT INTO listofsymbols VALUES ('" + symbolArray[i] + "');");
   }
   conn.close();
 }
Beispiel #2
0
  /**
   * Creates the database, deleting data that existed previously.
   *
   * <p>Won't actually remove symbol's tables if they aren't in the set SYMBOLS.
   *
   * @param pauseDuration - this is how long we sleep (in ms) for before hitting yahoo again
   * @see SYMBOLS
   */
  public static void createDatabase(String[] symbolArray, int pauseDuration) {
    try {
      Connection conn = initialize();
      Statement stat = conn.createStatement();
      try {
        stat.executeUpdate("DROP TABLE IF EXISTS " + "listofsymbols" + ";");
        stat.executeUpdate(
            "CREATE TABLE IF NOT EXISTS " + "listofsymbols" + " (" + "'symbolname'" + ");");
      } catch (Exception e) {
        System.out.println("failed stat.executeUpdate");
        System.out.println(e.getMessage());
      }

      for (int i = 0; i < symbolArray.length; i++) {
        addSymbol(symbolArray[i]);
        if (pauseDuration != 0) {
          Thread.sleep(pauseDuration);
        }
      }
      conn.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }