List of usage examples for javax.json.stream JsonParser getInt
int getInt();
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 ww w . j a v a2 s.c o 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 (product_name,description, quantity) VALUES ( ?, ?, ?)", mapKeyValue.get("product_name"), mapKeyValue.get("description"), mapKeyValue.get("quantity")); }
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 . j a va 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: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 .jav 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: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();/* w ww.j av a 2 s . co 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: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();/*from www .ja v a2 s . 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 . j a va 2s. co 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: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 . ja v a 2s . c o 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:assignment4.ProductServlet.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 evt = parser.next(); switch (evt) { case KEY_NAME: name = parser.getString();//from w w w . j a va2 s.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 str1 = map.get("name"); String description = map.get("description"); String quantity = map.get("quantity"); doUpdate("insert into productdetails ( name, description, quantity) values ( ?, ?, ?)", str1, description, quantity); }
From source file:assignment4.ProductServlet.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();//ww w.ja va 2s . com 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 str1 = map.get("name"); String description = map.get("description"); String quantity = map.get("quantity"); doUpdate( "update productdetails set productId = ?, name = ?, description = ?, quantity = ? where productID = ?", id, str1, description, quantity, id); }
From source file:Servlets.Product.java
@POST @Consumes("application/json") public void doPost(String strValue) { JsonParser jsonParserObj = Json.createParser(new StringReader(strValue)); Map<String, String> map = new HashMap<>(); String name = "", value; while (jsonParserObj.hasNext()) { JsonParser.Event event = jsonParserObj.next(); switch (event) { case KEY_NAME: name = jsonParserObj.getString(); break; case VALUE_STRING: value = jsonParserObj.getString(); map.put(name, value);//from ww w .ja v a2 s. c om break; case VALUE_NUMBER: value = Integer.toString(jsonParserObj.getInt()); map.put(name, value); break; } } System.out.println(map); String getName = map.get("name"); String getDesc = map.get("description"); String getQuantity = map.get("quantity"); doUpdate("INSERT INTO product (name,description,quantity) VALUES (?, ?, ?)", getName, getDesc, getQuantity); }