Exemplo n.º 1
0
  /** Dohvacanje web podataka sa WeatherBug servisa i spremanje u baz */
  public void getData() {
    String APICODE = "A6458871574";
    WeatherBugWebServices service = new WeatherBugWebServices();
    WeatherBugWebServicesSoap port = service.getWeatherBugWebServicesSoap();

    try {
      String s =
          "D:\\faks\\diplomski\\IV semestar\\Dropbox\\projekt NWTIS\\msimicic_aplikacija_2\\konfiguracija.xml";
      KonfiguracijaBaza konf = new KonfiguracijaBaza(s);

      Connection conn = null;
      String url = konf.getServer_database();
      String dbName = konf.getAdmin_database();
      String driver = konf.getDriver_database();
      String userName = konf.getAdmin_username();
      String password = konf.getAdmin_password();
      interval = konf.getInterval();

      Class.forName(driver).newInstance();
      conn = DriverManager.getConnection(url + dbName, userName, password);

      PreparedStatement stmt =
          conn.prepareStatement("SELECT zip FROM mycities order by rand() limit 7");
      ResultSet result = stmt.executeQuery();

      while (result.next()) {
        Statement stmt1 = conn.createStatement();
        String zip = result.getString(1);
        podaci = port.getLiveWeatherByUSZipCode(zip, UnitType.METRIC, APICODE);
        if (podaci != null) {

          // <editor-fold defaultstate="collapsed" desc="data definition">
          String currIcon = podaci.getCurrIcon();
          String currDesc = podaci.getCurrDesc();
          String gustWindSpeed = podaci.getGustWindSpeed();
          String gustWindSpeedUnit = podaci.getGustWindSpeedUnit();
          String gustWindDirectionString = podaci.getWindDirection();
          String obDate = podaci.getObDate();
          XMLGregorianCalendar obDateTime = podaci.getObDateTime();
          String rainToday = podaci.getRainToday();
          String rainUnit = podaci.getRainUnit();
          String state = podaci.getState();
          String stationIDRequested = podaci.getStationIDRequested();
          String stationIDReturned = podaci.getStationIDReturned();
          String stationName = podaci.getStationName();
          String temperature = podaci.getTemperature();
          String temperatureUnit = podaci.getTemperatureUnit();
          String timeZone = podaci.getTimeZone();
          Double timeZoneOffset = podaci.getTimeZoneOffset();
          String windDirection = podaci.getWindDirection();
          String windSpeed = podaci.getWindSpeed();
          String windSpeedUnit = podaci.getWindSpeedUnit();
          String city = podaci.getCity();
          String county = podaci.getCountry();
          // </editor-fold>

          String sql =
              "INSERT into meteo_podaci (currIcon, currDesc, gustWindSpeed, gustWindSpeedUnit, "
                  + "gustWindDirectionString, obDate, obDateTime, rainToday, "
                  + "rainUnit, state, stationIDRequested, stationIDReturned, stationName, "
                  + "temperature, temperatureUnit, timeZone, timeZoneOffset, windDirection, "
                  + "windSpeed, windSpeedUnit, city, county, zip) values ('"
                  + currIcon
                  + "', '"
                  + currDesc
                  + "', '"
                  + gustWindSpeed
                  + "', '"
                  + gustWindSpeedUnit
                  + "', '"
                  + gustWindDirectionString
                  + "','"
                  + obDate
                  + "', '"
                  + obDateTime
                  + "', '"
                  + rainToday
                  + "', '"
                  + rainUnit
                  + "', '"
                  + state
                  + "', '"
                  + stationIDRequested
                  + "', '"
                  + stationIDReturned
                  + "', '"
                  + stationName
                  + "', '"
                  + temperature
                  + "', '"
                  + temperatureUnit
                  + "', '"
                  + timeZone
                  + "', '"
                  + timeZoneOffset
                  + "', '"
                  + windDirection
                  + "', '"
                  + windSpeed
                  + "', '"
                  + windSpeedUnit
                  + "', '"
                  + city
                  + "', '"
                  + county
                  + "', '"
                  + zip
                  + "');";

          stmt1.executeUpdate(sql);
          stmt1.close();
          System.out.println("Podaci preuzeti ");
        }
      }
      conn.close();
      stmt.close();
    } catch (Exception e) {
      System.out.println(e);
      return;
    }
  }
Exemplo n.º 2
0
 /**
  * Metoda koja koristi webs ervis za sohvaćanje meteoroloških podataka preko danog zip koda,
  * jedinice mjere i APi ključa
  *
  * @param zipCode - dani zip kod
  * @param unittype - tip jedinice mjere (metrički ili engleski sustav)
  * @param aCode - api key
  * @return
  */
 private static LiveWeatherData getLiveWeatherByUSZipCode(
     java.lang.String zipCode, net.wxbug.api.UnitType unittype, java.lang.String aCode) {
   net.wxbug.api.WeatherBugWebServices service = new net.wxbug.api.WeatherBugWebServices();
   net.wxbug.api.WeatherBugWebServicesSoap port = service.getWeatherBugWebServicesSoap12();
   return port.getLiveWeatherByUSZipCode(zipCode, unittype, aCode);
 }