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.mirth.connect.connectors.jdbc.DatabaseDispatcherTests.java
private void initTables() throws SQLException { Statement statement = connection.createStatement(); if (TestUtils.tableExists(connection, TABLE1)) { statement.executeUpdate("DROP TABLE " + TABLE1); }/* ww w. j av a2 s. c o m*/ if (TestUtils.tableExists(connection, TABLE2)) { statement.executeUpdate("DROP TABLE " + TABLE2); } statement.executeUpdate("CREATE TABLE " + TABLE1 + " (mypatientid integer NOT NULL, lastname varchar(64) NOT NULL, firstname varchar(64) NOT NULL, gender character varying(1) NOT NULL, dateofbirth date NOT NULL)"); statement.executeUpdate("CREATE TABLE " + TABLE2 + " (mypatientid integer NOT NULL, lastname varchar(64) NOT NULL, firstname varchar(64) NOT NULL, gender character varying(1) NOT NULL, dateofbirth date NOT NULL)"); statement.close(); }
From source file:com.aerothai.database.servicemethod.ServicemethodService.java
/** * Method to check whether uname and pwd combination are correct * /*from w w w . j av a 2 s. co m*/ * @param uname * @param pwd * @return * @throws Exception */ public String createServicemethod(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.aerothai.database.servicetype.ServicetypeService.java
/** * Method to check whether uname and pwd combination are correct * //from w w w .j av a 2s. c o m * @param uname * @param pwd * @return * @throws Exception */ public String createServicetype(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:Phnbk.java
private void populate(Statement statement, String s, int i, String tableName) throws SQLException { String tempo;// w w w. jav a 2s. c o m if (s != null) { for (String retval : s.split(",")) { tempo = " INSERT INTO " + tableName + " (id, number) VALUES ('" + i + "','" + retval + "')"; statement.executeUpdate(tempo); } } }
From source file:com.cloudera.sqoop.testutil.HsqldbTestServer.java
public void createEmployeeDemo() throws SQLException, ClassNotFoundException { Class.forName(DRIVER_CLASS);//from w w w . j ava 2 s .c o m Connection connection = null; Statement st = null; try { connection = getConnection(); st = connection.createStatement(); st.executeUpdate("DROP TABLE " + EMPLOYEE_TABLE_NAME + " IF EXISTS"); st.executeUpdate( "CREATE TABLE " + EMPLOYEE_TABLE_NAME + "(emp_id INT NOT NULL PRIMARY KEY, name VARCHAR(64))"); st.executeUpdate("INSERT INTO " + EMPLOYEE_TABLE_NAME + " VALUES(1, 'Aaron')"); st.executeUpdate("INSERT INTO " + EMPLOYEE_TABLE_NAME + " VALUES(2, 'Joe')"); st.executeUpdate("INSERT INTO " + EMPLOYEE_TABLE_NAME + " VALUES(3, 'Jim')"); st.executeUpdate("INSERT INTO " + EMPLOYEE_TABLE_NAME + " VALUES(4, 'Lisa')"); connection.commit(); } finally { if (null != st) { st.close(); } if (null != connection) { connection.close(); } } }
From source file:com.aerothai.database.accessory.AccessoryService.java
/** * Method to check whether uname and pwd combination are correct * /*from w w w. java 2s .c o m*/ * @param uname * @param pwd * @return * @throws Exception */ public boolean updateSql(String query) throws Exception { boolean isDone = false; Connection dbConn = null; try { dbConn = DBConnection.createConnection(); Statement stmt = dbConn.createStatement(); System.out.println(query); stmt.executeUpdate(query); isDone = 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 isDone; }
From source file:com.github.gaoyangthu.demo.mapred.DBCountPageView.java
private void dropTables() { String dropAccess = "DROP TABLE Access"; String dropPageview = "DROP TABLE Pageview"; try {// ww w . jav a 2s . co m Statement st = connection.createStatement(); st.executeUpdate(dropAccess); st.executeUpdate(dropPageview); connection.commit(); st.close(); } catch (SQLException ex) { //ignore } }
From source file:com.aerothai.database.accessory.AccessoryService.java
/** * Method to check whether uname and pwd combination are correct * * @param uname/* w ww. ja va 2 s. c om*/ * @param pwd * @return * @throws Exception */ public String updateAccessory(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", "update"); 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.aerothai.database.accessory.AccessoryService.java
/** * Method to check whether uname and pwd combination are correct * // ww w. j a va 2 s .co m * @param uname * @param pwd * @return * @throws Exception */ public String deleteAccessory(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.aerothai.database.model.ModelService.java
/** * Method to check whether uname and pwd combination are correct * * @param uname// ww w . j av a2 s . com * @param pwd * @return * @throws Exception */ public String updateModel(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", "update"); 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(); }