SHARE
TWEET

Untitled

a guest May 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     @POST
  2.     @Produces(MediaType.APPLICATION_JSON)
  3.     @Consumes(MediaType.APPLICATION_JSON)
  4.     public String postJson(String podaci) {
  5.         JsonReader reader = Json.createReader(new StringReader(podaci));
  6.         javax.json.JsonObject jsonPodaci = reader.readObject();
  7.         JsonObject jsonObject = new JsonObject();
  8.         if (!jsonPodaci.containsKey("icao")) {
  9.             jsonObject.addProperty("odgovor", "Nije poslan icao parametar");
  10.             jsonObject.addProperty("status", "ERR");
  11.             return jsonObject.toString();
  12.         }
  13.         String icao = jsonPodaci.getString("icao");
  14.  
  15.         try {
  16.             BP_Konfiguracija bp_konf = (BP_Konfiguracija) sc.getAttribute("BP_Konfig");
  17.             Class.forName(bp_konf.getDriverDatabase());
  18.  
  19.             String query = "SELECT * FROM AIRPORTS WHERE IDENT = '" + icao + "'";
  20.             try (Connection c = DriverManager.getConnection(bp_konf.getServerDatabase() + bp_konf.getUserDatabase(), bp_konf.getUserUsername(), bp_konf.getUserPassword());) {
  21.                 Statement s = c.createStatement();
  22.                 ResultSet rs = s.executeQuery(query);
  23.                 rs.next();
  24.                 query = "INSERT INTO MYAIRPORTS (IDENT, NAME, ISO_COUNTRY, COORDINATES, STORED) VALUES ('" + rs.getString("IDENT") + "', '" + rs.getString("NAME") + "', '" + rs.getString("ISO_COUNTRY") + "', '" + rs.getString("COORDINATES") + "', CURRENT_TIMESTAMP)";
  25.                 s = c.createStatement();
  26.                 s.execute(query);
  27.  
  28.                 jsonObject.addProperty("odgovor", "Aerodrom uspješno dodan");
  29.                 jsonObject.addProperty("status", "OK");
  30.             } catch (SQLException ex) {
  31.                 jsonObject.addProperty("poruka", "Aerodrom je već dodan ili ne postoji");
  32.                 jsonObject.addProperty("status", "ERR");
  33.             }
  34.         } catch (ClassNotFoundException ex) {
  35.             jsonObject.addProperty("poruka", "Greška kod spajanja na bazu");
  36.             jsonObject.addProperty("status", "ERR");
  37.         }
  38.         return jsonObject.toString();
  39.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top