Example usage for javax.json.stream JsonParser getString

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

Introduction

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

Prototype

String getString();

Source Link

Document

Returns a String for the name in a name/value pair, for a string value or a number value.

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();
            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;
        }//  ww  w  .  j  av  a 2s  . c o m
    }
    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();
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }/*from  ww w .j av  a 2  s .  co  m*/
    }
    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();
            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;
        }//  w  ww. jav  a  2 s  .  co m
    }
    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();
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }// w  ww .j  a v  a  2  s.  c  om
    }
    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: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. ja  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("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  ww  w.ja  va  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: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();
            break;
        case VALUE_STRING:
            value = parser.getString();/* www  .  j  av  a 2  s .c o  m*/
            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();
            break;
        case VALUE_STRING:
            value = parser.getString();/*from  w  w  w  .  j  a va2 s  . c o  m*/
            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: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();
            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;
        }/*from   w  w  w.  j ava 2s .  c o  m*/
    }
    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();
            break;
        case VALUE_STRING:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        case VALUE_NUMBER:
            val = parser.getString();
            mapKayValue.put(key, val);
            break;
        }//from  w w  w  .j a  v a  2s.  c om
    }
    System.out.println(mapKayValue);
    doPostOrPutOrDelete("UPDATE PRODUCT SET name = ?, description = ?, quantity = ? WHERE productID = ?",
            mapKayValue.get("name"), mapKayValue.get("description"), mapKayValue.get("quantity"), id);

}