예제 #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 logPacket(byte[] packet) {
    Date date = new Date();
    Timestamp ts = new Timestamp(date.getTime());
    String dataField = "time";
    String dataValue = "'" + ts + "'";

    int[] intPacket = new int[packet.length];
    for (int i = 0; i < packet.length; i++) {
      if (packet[i] < 0) intPacket[i] = (int) packet[i] + 256;
      else intPacket[i] = (int) packet[i];
    }

    for (int i = 0; i < intPacket.length; i++) {
      dataField += ", " + "b" + Integer.toString(i);
      dataValue += ", '" + intPacket[i] + "'";
    }
    String queryString = "insert into " + tablename + " (" + dataField + ") VALUES ( ";
    queryString += dataValue + ");";
    try {
      query.executeUpdate(queryString);
    } catch (SQLException e) {
      System.out.println("Query no good; " + e.getErrorCode() + "; " + queryString);
    }
  }