List of usage examples for javax.json.stream JsonParser getString
String getString();
From source file:com.oracle.products.ProductResource.java
@PUT @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)// ww w. j ava2 s. c o m public String putProduct(@PathParam("id") int id, String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> productMap = new LinkedHashMap<>(); String key = ""; String val = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: val = parser.getString(); productMap.put(key, val); break; case VALUE_NUMBER: val = parser.getString(); productMap.put(key, val); break; default: break; } } if (conn == null) { return "Not connected"; } else { String query = "UPDATE product SET name = ?, description = ?, quantity = ? WHERE product_id =?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setString(1, productMap.get("name")); pstmt.setString(2, productMap.get("description")); pstmt.setInt(3, Integer.parseInt(productMap.get("quantity"))); pstmt.setInt(4, id); pstmt.executeUpdate(); return "row has been updated into the database"; } }
From source file:com.Assignment4.Assign.java
@POST @Consumes(MediaType.APPLICATION_JSON)//from w ww . j a v a2s.co m @Produces(MediaType.TEXT_PLAIN) public String postProduct(String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> proMap = new LinkedHashMap<String, String>(); String key = ""; String val = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: val = parser.getString(); proMap.put(key, val); break; case VALUE_NUMBER: val = parser.getString(); proMap.put(key, val); break; default: break; } } if (connected == null) { return "Not connected"; } else { String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)"; PreparedStatement pst = connected.prepareStatement(query); pst.setInt(1, Integer.parseInt(proMap.get("product_id"))); pst.setString(2, proMap.get("name")); pst.setString(3, proMap.get("description")); pst.setInt(4, Integer.parseInt(proMap.get("quantity"))); pst.executeUpdate(); return "row has been inserted into the database"; } }
From source file:com.product.Product.java
@PUT @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)//from w ww . j a v a 2 s. c o m public String putProduct(@PathParam("id") int id, String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> prodMap = new LinkedHashMap<String, String>(); String key = ""; String val = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: val = parser.getString(); prodMap.put(key, val); break; case VALUE_NUMBER: val = parser.getString(); prodMap.put(key, val); break; default: break; } } if (connect == null) { return "Not connected"; } else { String query = "UPDATE product SET name = ?, description = ?, quantity = ? WHERE product_id =?"; PreparedStatement prepstmnt = connect.prepareStatement(query); prepstmnt.setString(1, prodMap.get("name")); prepstmnt.setString(2, prodMap.get("description")); prepstmnt.setInt(3, Integer.parseInt(prodMap.get("quantity"))); prepstmnt.setInt(4, id); prepstmnt.executeUpdate(); return "row has been updated into the database"; } }
From source file:com.product.Product.java
@POST @Path("/products") @Consumes(MediaType.APPLICATION_JSON)/*from w w w . ja v a 2 s. c o m*/ @Produces(MediaType.TEXT_PLAIN) public String postProduct(String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> prodMap = new LinkedHashMap<String, String>(); String key = ""; String val = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: val = parser.getString(); prodMap.put(key, val); break; case VALUE_NUMBER: val = parser.getString(); prodMap.put(key, val); break; default: break; } } if (connect == null) { return "Not connected"; } else { String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)"; PreparedStatement prepstmnt = connect.prepareStatement(query); prepstmnt.setInt(1, Integer.parseInt(prodMap.get("product_id"))); prepstmnt.setString(2, prodMap.get("name")); prepstmnt.setString(3, prodMap.get("description")); prepstmnt.setInt(4, Integer.parseInt(prodMap.get("quantity"))); prepstmnt.executeUpdate(); return "row has been inserted into the database"; } }
From source file:com.assignment4.productdetails.java
@PUT @Path("{id}") @Consumes(MediaType.APPLICATION_JSON)/*ww w. j a v a2 s . co m*/ public String putProduct(@PathParam("id") int id, String str) throws SQLException { JsonParser parse = Json.createParser(new StringReader(str)); Map<String, String> pdtmap = new LinkedHashMap<String, String>(); String key = ""; String value = ""; while (parse.hasNext()) { JsonParser.Event event = parse.next(); switch (event) { case KEY_NAME: key = parse.getString(); break; case VALUE_STRING: value = parse.getString(); pdtmap.put(key, value); break; case VALUE_NUMBER: value = parse.getString(); pdtmap.put(key, value); break; default: break; } } if (conn == null) { return "Not able to connect"; } else { String query = "UPDATE product SET name = ?, description = ?, quantity = ? WHERE product_id =?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setString(1, pdtmap.get("name")); pstmt.setString(2, pdtmap.get("description")); pstmt.setInt(3, Integer.parseInt(pdtmap.get("quantity"))); pstmt.setInt(4, id); pstmt.executeUpdate(); return "row has been updated into the database"; } }
From source file:com.products.ProductResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)//from w ww . j a va 2 s . c o m @Produces(MediaType.TEXT_PLAIN) public String postProduct(String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> productMap = new LinkedHashMap<String, String>(); String key = ""; String value = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: value = parser.getString(); productMap.put(key, value); break; case VALUE_NUMBER: value = parser.getString(); productMap.put(key, value); break; default: break; } } if (co == null) { return "Not connected"; } else { String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)"; PreparedStatement stmt = co.prepareStatement(query); stmt.setInt(1, Integer.parseInt(productMap.get("product_id"))); stmt.setString(2, productMap.get("name")); stmt.setString(3, productMap.get("description")); stmt.setInt(4, Integer.parseInt(productMap.get("quantity"))); stmt.executeUpdate(); return "row has been inserted into the database"; } }
From source file:com.oracle.products.ProductResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)/*w ww . jav a 2 s . co m*/ @Produces(MediaType.TEXT_PLAIN) public String postProduct(String str) throws SQLException { JsonParser parser = Json.createParser(new StringReader(str)); Map<String, String> productMap = new LinkedHashMap<String, String>(); String key = ""; String val = ""; while (parser.hasNext()) { JsonParser.Event event = parser.next(); switch (event) { case KEY_NAME: key = parser.getString(); break; case VALUE_STRING: val = parser.getString(); productMap.put(key, val); break; case VALUE_NUMBER: val = parser.getString(); productMap.put(key, val); break; default: break; } } if (conn == null) { return "Not connected"; } else { String query = "INSERT INTO product (product_id,name,description,quantity) VALUES (?,?,?,?)"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, Integer.parseInt(productMap.get("product_id"))); pstmt.setString(2, productMap.get("name")); pstmt.setString(3, productMap.get("description")); pstmt.setInt(4, Integer.parseInt(productMap.get("quantity"))); pstmt.executeUpdate(); return "row has been inserted into the database"; } }
From source file:com.assignment4.productdetails.java
@POST @Path("/products") @Consumes(MediaType.APPLICATION_JSON)/*from w ww .j av a2 s. co m*/ @Produces(MediaType.TEXT_PLAIN) public String postProduct(String string) throws SQLException { JsonParser parse = Json.createParser(new StringReader(string)); Map<String, String> pdtmap = new LinkedHashMap<String, String>(); String key = ""; String value = ""; while (parse.hasNext()) { JsonParser.Event event = parse.next(); switch (event) { case KEY_NAME: key = parse.getString(); break; case VALUE_STRING: value = parse.getString(); pdtmap.put(key, value); break; case VALUE_NUMBER: value = parse.getString(); pdtmap.put(key, value); break; default: break; } } if (conn == null) { return "Not able to connect"; } else { String query = "INSERT INTO products (product_id,name,decription,quantity) VALUES (?,?,?)"; PreparedStatement prestmt = conn.prepareStatement(query); prestmt.setInt(1, Integer.parseInt(pdtmap.get("product_id"))); prestmt.setString(2, pdtmap.get("name")); prestmt.setString(3, pdtmap.get("description")); prestmt.setInt(4, Integer.parseInt(pdtmap.get("quantity"))); prestmt.executeUpdate(); return " the row has been inserted into the database"; } }
From source file:com.seniorproject.semanticweb.services.WebServices.java
public String generateSparqlForAddProperty(String category, String property, String selectedValues) { String iri = getIRI(category); String queryString = "SELECT ?value ?label WHERE { "; queryString += "?subject rdf:type " + iri + " . "; if (selectedValues.length() > 0) { JsonParser parser = Json.createParser(new StringReader(selectedValues)); Event event = parser.next();// START_OBJECT while ((event = parser.next()) != Event.END_OBJECT) { if (parser.getString().substring(0, 2).equalsIgnoreCase("is")) { String[] parts = parser.getString().split(" "); event = parser.next();/* ww w.ja v a 2s . c o m*/ queryString += convertToNoPrefix(parser.getString()) + " " + parts[1] + " ?subject ."; } else { queryString += "?subject " + parser.getString() + " "; event = parser.next(); queryString += convertToNoPrefix(parser.getString()) + ". "; } } } if (property.substring(0, 2).equalsIgnoreCase("is")) { String[] parts = property.split(" "); queryString += "?value " + parts[1] + " ?subject . "; } else { queryString += "?subject " + property + " ?value . "; } queryString += "OPTIONAL {?value rdfs:label ?label. }} "; return queryString; }
From source file:com.seniorproject.semanticweb.services.WebServices.java
public String generateSparqlForSelectValue(String json, String category) { JsonParser parser = Json.createParser(new StringReader(json)); Event event = parser.next();// START_OBJECT String iri = getIRI(category); String queryString = "SELECT ?subject ?label WHERE { ?subject rdf:type " + iri + " . "; while ((event = parser.next()) != Event.END_OBJECT) { if (parser.getString().substring(0, 2).equalsIgnoreCase("is")) { String[] parts = parser.getString().split(" "); event = parser.next();/*from w w w . java 2 s .c om*/ String value = parser.getString(); value = convertToNoPrefix(value); queryString += value + " " + parts[1] + " ?subject ."; } else { queryString += "?subject " + parser.getString() + " "; event = parser.next(); String value = parser.getString(); value = convertToNoPrefix(value); queryString += value + ". "; } } queryString += "?subject rdfs:label ?label. }"; return queryString; }