예제 #1
0
  public static void duration() {
    connectDb();
    String sql = "select min(time), max(time), count(*) from " + tablename + ";";
    try {
      ResultSet rs = query.executeQuery(sql);
      rs.next();
      int numCols = rs.getMetaData().getColumnCount();
      String minTime = rs.getString(1);
      String maxTime = rs.getString(2);
      String numPackets = rs.getString(3);
      System.out.println(
          "Experiment "
              + tablename
              + "\n\tfrom: "
              + minTime
              + "\n\tto: "
              + maxTime
              + "\n\tpackets: "
              + numPackets);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
  }
예제 #2
0
  public static void clearTable() {
    connectDb();
    String sql = "delete from " + tablename + ";";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Table Cleared Successfully");
  }
예제 #3
0
  public static void createTable() {
    connectDb();
    String dataField = "";
    for (int i = 0; i < AM_HEADER_LENGTH + TOSH_DATA_LENGTH + CRC_LENGTH; i++) {
      dataField = dataField + ", " + "b" + Integer.toString(i) + " smallint";
    }
    String sql =
        "create table "
            + tablename
            + " (time timestamp without time zone, packetid serial"
            + dataField;
    sql += ", primary key (packetid) );";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Initialise Table Successfully");
  }
예제 #4
0
  static void listen() {
    if (doLogging == true) {
      // first we connect to the database first
      connectDb();
    }
    PacketSource reader = BuildSource.makePacketSource(source);

    if (reader == null) {
      System.out.println("Cannot connect to destination.");
      System.out.println("Did you forget to do network@ip:port? Destination maybe wrong or busy");
    }
    try {
      reader.open(PrintStreamMessenger.err);

      for (; ; ) {
        byte[] packet = reader.readPacket();
        if (doLogging == true) logPacket(packet);
        if (doDisplay == true) PrettyPrint.print(packet);
        System.out.println();
      }
    } catch (IOException e) {
      System.err.println("Error on " + reader.getName() + ": " + e);
    }
  }