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.aerothai.database.dept.DeptService.java
/** * Method to check whether uname and pwd combination are correct * // w w w .j a v a2 s .c om * @param uname * @param pwd * @return * @throws Exception */ public String deleteDept(String query) throws Exception { Connection dbConn = null; JSONObject obj = new JSONObject(); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); System.out.println(query); stmt.executeUpdate(query); obj.put("tag", "delete"); obj.put("msg", "done"); obj.put("status", true); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj.toJSONString(); }
From source file:com.cloudera.sqoop.testutil.HsqldbTestServer.java
/** * Delete any existing tables.//from www.ja v a2 s. c o m */ public void dropExistingSchema() throws SQLException { ConnManager mgr = getManager(); String[] tables = mgr.listTables(); if (null != tables) { Connection conn = mgr.getConnection(); for (String table : tables) { Statement s = conn.createStatement(); try { s.executeUpdate("DROP TABLE " + table); conn.commit(); } finally { s.close(); } } } }
From source file:com.aerothai.database.dept.DeptService.java
/** * Method to check whether uname and pwd combination are correct * /*from www. j a v a 2s . co m*/ * @param uname * @param pwd * @return * @throws Exception */ public String createDept(String query) throws Exception { Connection dbConn = null; JSONObject obj = new JSONObject(); obj.put("msg", "error"); obj.put("status", false); try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); System.out.println(query); stmt.executeUpdate(query); obj.put("tag", "create"); obj.put("msg", "done"); obj.put("status", true); } catch (SQLException sqle) { throw sqle; } catch (Exception e) { // TODO Auto-generated catch block if (dbConn != null) { dbConn.close(); } throw e; } finally { if (dbConn != null) { dbConn.close(); } } return obj.toJSONString(); }
From source file:com.bt.aloha.testing.JdbcHelper.java
protected int executeUpdate(DataSource ds, String createScript) throws SQLException { Connection conn = null;//from www. ja v a 2 s .c o m Statement st = null; int rowCount = -1; try { conn = DataSourceUtils.getConnection(ds); st = conn.createStatement(); rowCount = st.executeUpdate(createScript); assert rowCount > 0; } catch (SQLException e) { log.warn("Unable to execute create sctipt: " + e.getMessage()); } finally { try { if (st != null) st.close(); } catch (SQLException e) { throw new RuntimeException(e); } finally { if (conn != null) DataSourceUtils.releaseConnection(conn, ds); } } return rowCount; }
From source file:io.hakbot.controller.resources.v1.BaseResourceTest.java
@After @SuppressWarnings("unchecked") public void after() throws Exception { PersistenceManager pm = PersistenceManagerFactory.createPersistenceManager(); JDOConnection jdoConnection = pm.getDataStoreConnection(); Connection conn = null;/*from w w w . j ava 2s . c om*/ Statement stmt = null; try { conn = (Connection) jdoConnection.getNativeConnection(); stmt = conn.createStatement(); stmt.executeUpdate("DROP ALL OBJECTS DELETE FILES"); } finally { if (conn != null) { conn.close(); } if (stmt != null) { stmt.close(); } } pm.close(); }
From source file:com.cloudera.sqoop.orm.TestClassWriter.java
@Test public void testWeirdColumnNames() throws SQLException { // Recreate the table with column names that aren't legal Java identifiers. String tableName = HsqldbTestServer.getTableName(); Connection connection = testServer.getConnection(); Statement st = connection.createStatement(); try {/* ww w . j a v a 2 s.c o m*/ st.executeUpdate("DROP TABLE " + tableName + " IF EXISTS"); st.executeUpdate("CREATE TABLE " + tableName + " (class INT, \"9field\" INT)"); st.executeUpdate("INSERT INTO " + tableName + " VALUES(42, 41)"); connection.commit(); } finally { st.close(); connection.close(); } String[] argv = { "--bindir", JAR_GEN_DIR, "--outdir", CODE_GEN_DIR, "--package-name", OVERRIDE_PACKAGE_NAME, }; runGenerationTest(argv, OVERRIDE_PACKAGE_NAME + "." + HsqldbTestServer.getTableName()); }
From source file:com.Jax.GenericResource.java
@POST @Consumes(MediaType.APPLICATION_JSON)//from w ww . j ava 2 s .co m @Produces(MediaType.APPLICATION_JSON) @Path("/post") public void createProduct(String content) throws ParseException, SQLException { JSONParser parser = new JSONParser(); JSONObject json = (JSONObject) parser.parse(content); Object id = json.get("id"); String newProductID = id.toString(); int productID = Integer.parseInt(newProductID); Object newName = json.get("newName"); String name = newName.toString(); Object newDescription = json.get("newDescription"); String description = newDescription.toString(); Object qty = json.get("qty"); String newQty = qty.toString(); int quantity = Integer.parseInt(newQty); Statement stmt = con.createStatement(); String query = "INSERT INTO products VALUES('" + productID + "','" + newName + "','" + newDescription + "','" + quantity + "')"; stmt.executeUpdate(query); }
From source file:com.oracle.tutorial.jdbc.RSSFeedsTable.java
public void dropTable() throws SQLException { Statement stmt = null; try {//www . java2s . c o m stmt = con.createStatement(); if (this.dbms.equals("mysql")) { stmt.executeUpdate("DROP TABLE IF EXISTS RSS_FEEDS"); } else if (this.dbms.equals("derby")) { stmt.executeUpdate("DROP TABLE RSS_FEEDS"); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { stmt.close(); } }
From source file:com.oracle.tutorial.jdbc.SuppliersTable.java
public void dropTable() throws SQLException { Statement stmt = null; try {// www .ja va2s . c o m stmt = con.createStatement(); if (this.dbms.equals("mysql")) { System.out.println("Dropping table SUPPLIERS from MySQL"); stmt.executeUpdate("DROP TABLE IF EXISTS SUPPLIERS"); } else if (this.dbms.equals("derby")) { stmt.executeUpdate("DROP TABLE SUPPLIERS"); } } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } finally { if (stmt != null) { stmt.close(); } } }
From source file:co.marcin.novaguilds.impl.storage.AbstractDatabaseStorage.java
/** * Adds tables to the database//from w ww .j a v a2 s .c om */ protected void setupTables() throws SQLException, IOException { for (String tableCode : getSqlActions()) { Statement statement = getConnection().createStatement(); statement.executeUpdate(tableCode); LoggerUtils.info("Table added to the database!"); } }