Example usage for javax.json.stream JsonParser hasNext

List of usage examples for javax.json.stream JsonParser hasNext

Introduction

In this page you can find the example usage for javax.json.stream JsonParser hasNext.

Prototype

boolean hasNext();

Source Link

Document

Returns true if there are more parsing states.

Usage

From source file:ASSINGMENT4.ServletProducts.java

@POST
@Consumes("application/json")
public void doPost(String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKeyValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();//from www .j  a v a 2 s. com
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKeyValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = Integer.toString(parser.getInt());
            mapKeyValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKeyValue);
    doPostOrPutOrDelete("INSERT INTO product (product_name,description, quantity) VALUES ( ?, ?, ?)",
            mapKeyValue.get("product_name"), mapKeyValue.get("description"), mapKeyValue.get("quantity"));
}

From source file:ASSINGMENT4.ServletProducts.java

@PUT
@Path("{product_id}")
@Consumes("application/json")
public void doPut(@PathParam("product_id") String id, String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKayValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();//from w ww .  j a va2  s .com
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKayValue);
    doPostOrPutOrDelete("UPDATE PRODUCT SET name = ?, description = ?, quantity = ? WHERE product_id = ?",
            mapKayValue.get("product_name"), mapKayValue.get("description"), mapKayValue.get("quantity"), id);

}

From source file:com.assignment.Product.java

@POST
@Consumes("application/json")
public void doPost(String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKeyValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();//w ww. jav a  2s. c om
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKeyValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = Integer.toString(parser.getInt());
            mapKeyValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKeyValue);
    doPostOrPutOrDelete("INSERT INTO products (name, description, quantity) VALUES ( ?, ?, ?)",
            mapKeyValue.get("name"), mapKeyValue.get("description"), mapKeyValue.get("quantity"));
}

From source file:com.assignment.Product.java

@PUT
@Path("{id}")
@Consumes("application/json")
public void doPut(@PathParam("id") String id, String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKayValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();//from   w w w  .  j  ava 2 s  .  c o  m
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKayValue);
    doPostOrPutOrDelete("UPDATE PRODUCTS SET name = ?, description = ?, quantity = ? WHERE productID = ?",
            mapKayValue.get("name"), mapKayValue.get("description"), mapKayValue.get("quantity"), id);

}

From source file:Servlet.product.java

@POST
@Consumes("application/json")
public void doPost(String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> map = new HashMap<>();
    String name = "", value;

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            name = parser.getString();/*  ww  w.ja  v a2s  .c  o  m*/
            break;
        case VALUE_STRING:
            value = parser.getString();
            map.put(name, value);
            break;
        case VALUE_NUMBER:
            value = Integer.toString(parser.getInt());
            map.put(name, value);
            break;
        }
    }
    System.out.println(map);

    String na = map.get("name");
    String des = map.get("description");
    String qunt = map.get("quantity");

    doUpdate("INSERT INTO product (name,description,quantity)VALUES (?,?,?)", na, des, qunt);
}

From source file:Servlet.product.java

@PUT
@Path("{id}")
@Consumes("application/json")
public void doPut(@PathParam("id") String id, String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> map = new HashMap<>();
    String name = "", value;

    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        switch (event) {
        case KEY_NAME:
            name = parser.getString();/*w ww .ja va 2s  .  c  o  m*/
            break;
        case VALUE_STRING:
            value = parser.getString();
            map.put(name, value);
            break;
        case VALUE_NUMBER:
            value = Integer.toString(parser.getInt());
            map.put(name, value);
            break;
        }
    }
    System.out.println(map);

    String na = map.get("name");
    String des = map.get("description");
    String qunt = map.get("quantity");

    doUpdate("update product set productID = ?, name = ?, description = ?, quantity = ? where productID = ?",
            id, na, des, qunt, id);
}

From source file:servlets.SampleServlet.java

@POST
@Consumes("application/json")
public void doPost(String st) {
    JsonParser parser = Json.createParser(new StringReader(st));
    Map<String, String> ad = new HashMap<>();
    String Name = "", value;

    while (parser.hasNext()) {
        JsonParser.Event e = parser.next();
        switch (e) {
        case KEY_NAME:
            Name = parser.getString();
            break;
        case VALUE_STRING:

            value = parser.getString();/*from  ww  w. jav a  2  s.  c om*/
            ad.put(Name, value);
            break;
        case VALUE_NUMBER:
            value = Integer.toString(parser.getInt());
            ad.put(Name, value);
            break;
        }
    }
    System.out.println(ad);
    String Name1 = ad.get("Name");
    String Description = ad.get("Description");
    String Quantity = ad.get("Quantity");
    doUpdate("INSERT INTO PRODUCT ( Name, Description, Quantity) values ( ?, ?, ?)", Name1, Description,
            Quantity);
}

From source file:servlets.SampleServlet.java

@PUT
@Path("{productID}")
@Consumes("application/json")
public void doPut(@PathParam("productID") String productID, String st) {
    JsonParser parser = Json.createParser(new StringReader(st));
    Map<String, String> ad = new HashMap<>();
    String Name = "", value;
    while (parser.hasNext()) {
        JsonParser.Event e = parser.next();
        switch (e) {
        case KEY_NAME:
            Name = parser.getString();
            break;
        case VALUE_STRING:
            value = parser.getString();//from  w  ww  .  j a v a 2  s  . c o  m
            ad.put(Name, value);
            break;
        case VALUE_NUMBER:
            value = Integer.toString(parser.getInt());
            ad.put(Name, value);
            break;
        }
    }
    System.out.println(ad);

    String Name1 = ad.get("Name");
    String Description = ad.get("Description");
    String Quantity = ad.get("Quantity");
    doUpdate("UPDATE PRODUCT SET productId = ?, Name = ?, Description = ?, Quantity = ? WHERE productID = ?",
            productID, Name1, Description, Quantity, productID);

}

From source file:com.products.products.java

@POST
@Consumes("application/json")
public void doPost(String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKeyValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();/*from  ww  w  .  j  a  v a  2s.co  m*/
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKeyValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = Integer.toString(parser.getInt());
            mapKeyValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKeyValue);
    doPostOrPutOrDelete("INSERT INTO product (name, description, quantity) VALUES ( ?, ?, ?)",
            mapKeyValue.get("name"), mapKeyValue.get("description"), mapKeyValue.get("quantity"));
}

From source file:com.products.products.java

@PUT
@Path("{id}")
@Consumes("application/json")
public void doPut(@PathParam("id") String id, String str) {
    JsonParser parser = Json.createParser(new StringReader(str));
    Map<String, String> mapKayValue = new HashMap<>();
    String key = "", val;
    while (parser.hasNext()) {
        JsonParser.Event evt = parser.next();
        switch (evt) {
        case KEY_NAME:
            key = parser.getString();//from   w w w . j  av a2 s  . c om
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }
    }
    System.out.println(mapKayValue);
    doPostOrPutOrDelete("UPDATE PRODUCT SET name = ?, description = ?, quantity = ? WHERE productID = ?",
            mapKayValue.get("name"), mapKayValue.get("description"), mapKayValue.get("quantity"), id);

}