public static void main2(String[] args) {
    AdjacentLocListGenerator generator = new AdjacentLocListGenerator();
    Connection conn;
    try {
      conn = DataLoader.getBeijingConn();
      AdjacentLocList list = generator.getListFromDB(conn);

      conn.setAutoCommit(false);
      PreparedStatement stmt =
          conn.prepareStatement(
              "INSERT INTO AdjacentLocation_Clustered"
                  + "(SiteId1, SiteId2, UserCount, TotalCount)"
                  + "VALUES (?, ?, ?, ?)");
      for (Site loc : list.getSites().values()) {
        for (AdjacentLocPair pair : loc.getNextSites()) {
          int siteId1 = pair.getSite1().getSiteId();
          int siteId2 = pair.getSite2().getSiteId();
          if (pair.getUsersCount() == 0) continue;
          stmt.setInt(1, siteId1);
          stmt.setInt(2, siteId2);
          stmt.setInt(3, pair.getUsersCount());
          stmt.setInt(4, pair.getTotalCount());
          stmt.addBatch();
        }
        stmt.executeBatch();
        conn.commit();
        System.out.println(loc.getSiteId() + " succeed.");
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
예제 #2
0
 public boolean isSameLoc(Site loc) {
   return loc.getLatitude() == this.latitude && loc.getLongitude() == this.longitude;
 }