List of usage examples for java.sql Statement executeUpdate
int executeUpdate(String sql) throws SQLException;
INSERT
, UPDATE
, or DELETE
statement or an SQL statement that returns nothing, such as an SQL DDL statement. From source file:com.products.GenericResource.java
@DELETE @Path("/products") @Consumes(MediaType.APPLICATION_JSON)//from w ww. j a v a 2 s .co m @Produces(MediaType.APPLICATION_JSON) public void deleteProduct(String content) throws SQLException, ParseException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = databaseconnection.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }
From source file:com.products.GenericResource.java
/** * PUT method for updating or creating an instance of GenericResource * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. *//* w ww.j a v a 2 s . c o m*/ @POST @Path("/products1") @Consumes("application/json") @Produces(MediaType.TEXT_PLAIN) public void postJson(String content) throws ParseException, SQLException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = databaseconnection.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }
From source file:com.products.GenericResource.java
@PUT @Path("/products") @Consumes(MediaType.APPLICATION_JSON)//from w ww . j a va 2 s . c o m @Produces(MediaType.APPLICATION_JSON) public void putProduct(String content) throws SQLException, ParseException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = databaseconnection.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }
From source file:bookUtilities.RemoveBookServlet.java
private JSONObject removeBook(String bookId) { JSONObject messageToReturn = new JSONObject(); try {/*from w ww . j av a 2 s . c o m*/ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost;user=sa;password=nopw"); Statement st = con.createStatement(); String query = "UPDATE HardCover.dbo.Book " + "SET Active = 0 " + "WHERE BookUuid = '" + bookId + "';"; st.executeUpdate(query); messageToReturn.put("message", "success"); } catch (Exception e) { System.out.println(e.getMessage()); } return messageToReturn; }
From source file:org.silverpeas.migration.sqldomain.PasswordSizeIncreaseTest.java
protected void assertPasswordTypeFor(String domain) throws Exception { String tableName = "Domain" + domain + "_User"; Statement statement = null; try {/*from w ww . java2 s .c o m*/ statement = databaseTester.getConnection().getConnection().createStatement(); statement.executeUpdate("update " + tableName + " set password='" + longPassword() + "' where id=1"); } catch (Exception ex) { fail(ex.getMessage()); } finally { if (statement != null) { statement.close(); } } }
From source file:org.syncope.buildtools.H2StartStopListener.java
@Override public void contextInitialized(final ServletContextEvent sce) { ServletContext context = sce.getServletContext(); File workDir = (File) sce.getServletContext().getAttribute("javax.servlet.context.tempdir"); try {/* w w w. j a va 2s. c om*/ Server h2TestDb = new Server(); h2TestDb.runTool("-baseDir", workDir.getAbsolutePath(), "-tcp", "-tcpDaemon", "-web", "-webDaemon", "-webPort", sce.getServletContext().getInitParameter("testdb.webport")); context.setAttribute(H2_TESTDB, h2TestDb); } catch (SQLException e) { LOG.error("Could not start H2 test db", e); } WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context); DataSource datasource = ctx.getBean(DataSource.class); Connection conn = null; Statement stmt = null; try { conn = DataSourceUtils.getConnection(datasource); stmt = conn.createStatement(); stmt.executeUpdate("RUNSCRIPT FROM 'classpath:/testdb.sql'"); } catch (Exception e) { LOG.error("While loading data into testdb", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } DataSourceUtils.releaseConnection(conn, datasource); } }
From source file:com.netflix.config.sources.JDBCConfigurationSourceTest.java
/** * Set up code for the test//w w w . j a va 2s . co m * @param dbname * @return * @throws Throwable */ javax.sql.DataSource createDataConfigSource(String dbname) throws Throwable { EmbeddedDataSource40 ds = new EmbeddedDataSource40(); ds.setDatabaseName(dbname); ds.setCreateDatabase(dbname); ds.setCreateDatabase("create"); Connection con = null; try { con = ds.getConnection(); // Creating a database table Statement sta = null; try { sta = con.createStatement(); sta.executeUpdate("DROP TABLE MySiteProperties"); log.info("Table Dropped"); } catch (Exception e) { log.info("Table did not exist."); } finally { if (sta != null) { sta.close(); } } try { sta = con.createStatement(); sta.executeUpdate("CREATE TABLE MySiteProperties (property_key VARCHAR(20)," + " property_value VARCHAR(100))"); log.info("Table created."); sta.close(); } finally { if (sta != null) { sta.close(); } } try { sta = con.createStatement(); sta.executeUpdate("insert into MySiteProperties values ('prop1','value1')"); log.info("Properties for testing inserted"); sta.close(); } finally { if (sta != null) { sta.close(); } } } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { if (con != null) { con.close(); } } return ds; }
From source file:com.assignment4.GenericResource.java
@DELETE @Path("/products") @Consumes(MediaType.APPLICATION_JSON)/*from w ww.j a v a 2 s .c o m*/ @Produces(MediaType.APPLICATION_JSON) public void deleteProduct(String content) throws SQLException, ParseException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = database.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }
From source file:com.assignment4.GenericResource.java
/** * PUT method for updating or creating an instance of GenericResource * @param content representation for the resource * @return an HTTP response with content of the updated or created resource. *//* w w w. ja v a 2 s .c o m*/ @POST @Path("/products1") @Consumes("application/json") @Produces(MediaType.TEXT_PLAIN) public void postJson(String content) throws ParseException, SQLException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = database.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }
From source file:com.assignment4.GenericResource.java
@PUT @Path("/products") @Consumes(MediaType.APPLICATION_JSON)//from www .ja v a2 s . co m @Produces(MediaType.APPLICATION_JSON) public void putProduct(String content) throws SQLException, ParseException { JSONParser jp = new JSONParser(); JSONObject obj = (JSONObject) jp.parse(content); Object objid = obj.get("id"); String ProductID = objid.toString(); int id = Integer.parseInt(ProductID); Object objname = obj.get("name"); String name = objname.toString(); Object objdes = obj.get("description"); String description = objdes.toString(); Object objquantity = obj.get("quantity"); String quantity_new = objquantity.toString(); int quantity = Integer.parseInt(quantity_new); conn = database.getConnection(); // String query =""; String query = "insert into product(ProductID, name, description, quantity) values('" + id + "','" + name + "','" + description + "','" + quantity + "')"; Statement st = conn.createStatement(); st.executeUpdate(query); }