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.devicetype.DeviceTypeService.java
/** * Method to check whether uname and pwd combination are correct * /*from ww w . j a v a 2 s .c o m*/ * @param uname * @param pwd * @return * @throws Exception */ public String createDeviceType(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.cloudera.sqoop.manager.NetezzaImportManualTest.java
private void populateTable(String tableName) throws SQLException { Statement statement = conn.createStatement(); try {// w w w . ja v a 2s .com statement.executeUpdate( "INSERT INTO " + tableName + " VALUES(1,'Aaron','2009-05-14',1000000.00,TRUE,'engineering')"); statement.executeUpdate( "INSERT INTO " + tableName + " VALUES(2,'Bob','2009-04-20',400.00,TRUE,'sales')"); statement.executeUpdate( "INSERT INTO " + tableName + " VALUES(3,'Fred','2009-01-23',15.00,FALSE,'marketing')"); conn.commit(); } finally { statement.close(); } }
From source file:com.cloudera.sqoop.manager.NetezzaImportManualTest.java
private void populateTableWithNull(String tableName) throws SQLException { Statement statement = conn.createStatement(); try {/*from w ww. ja va2 s. c om*/ statement.executeUpdate("INSERT INTO " + tableName + " VALUES(1,'Aaron','2009-05-14',1000000.00,TRUE," + "'engineering',NULL,1)"); statement.executeUpdate( "INSERT INTO " + tableName + " VALUES(2,'Bob','2009-04-20',400.00,TRUE,'sales',NULL,2)"); statement.executeUpdate( "INSERT INTO " + tableName + " VALUES(3,'Fred','2009-01-23',15.00,FALSE,'marketing',NULL,3)"); conn.commit(); } finally { statement.close(); } }
From source file:io.undertow.server.handlers.JDBCLogDatabaseTestCase.java
@After public void teardown() throws SQLException { Connection conn = null;/*from ww w .ja v a 2 s .c o m*/ Statement statement = null; try { conn = ds.getConnection(); conn.setAutoCommit(true); statement = conn.createStatement(); statement.executeUpdate("DROP TABLE PUBLIC.ACCESS;"); } finally { if (statement != null) { statement.close(); } if (conn != null) { conn.close(); } } ds.dispose(); ds = null; }
From source file:com.aerothai.database.position.PositionService.java
/** * Method to check whether uname and pwd combination are correct * * @param uname//from w w w . j ava 2 s . c om * @param pwd * @return * @throws Exception */ public String updatePosition(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.position.PositionService.java
/** * Method to check whether uname and pwd combination are correct * // ww w . ja v a 2 s . co m * @param uname * @param pwd * @return * @throws Exception */ public String deletePosition(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:io.undertow.server.handlers.JDBCLogDatabaseTestCase.java
@Before public void setup() throws SQLException { ds = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "user", "password"); Connection conn = null;/* w ww. j ava 2 s. c o m*/ Statement statement = null; try { conn = ds.getConnection(); conn.setAutoCommit(true); statement = conn.createStatement(); statement.executeUpdate("CREATE TABLE PUBLIC.ACCESS (" + " id SERIAL NOT NULL," + " remoteHost CHAR(15) NOT NULL," + " userName CHAR(15)," + " timestamp TIMESTAMP NOT NULL," + " virtualHost VARCHAR(64)," + " method VARCHAR(8)," + " query VARCHAR(255) NOT NULL," + " status SMALLINT UNSIGNED NOT NULL," + " bytes INT UNSIGNED NOT NULL," + " referer VARCHAR(128)," + " userAgent VARCHAR(128)," + " PRIMARY KEY (id)" + " );"); } finally { if (statement != null) { statement.close(); } if (conn != null) { conn.close(); } } }
From source file:com.aerothai.database.position.PositionService.java
/** * Method to check whether uname and pwd combination are correct * /*from w w w .j a v a 2 s . co m*/ * @param uname * @param pwd * @return * @throws Exception */ public String createPosition(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.cloudera.sqoop.testutil.HsqldbTestServer.java
/** * Create a table.//from w w w .j a v a 2s . c o m */ public void createSchema() throws SQLException { Connection connection = null; Statement st = null; try { connection = getConnection(); st = connection.createStatement(); st.executeUpdate("DROP TABLE " + DUMMY_TABLE_NAME + " IF EXISTS"); st.executeUpdate("CREATE TABLE " + DUMMY_TABLE_NAME + "(intField1 INT, intField2 INT)"); connection.commit(); } finally { if (null != st) { st.close(); } if (null != connection) { connection.close(); } } }
From source file:com.aerothai.database.role.RoleService.java
/** * Method to check whether uname and pwd combination are correct * * @param uname//from w w w . ja v a2 s .c o m * @param pwd * @return * @throws Exception */ public String updateRole(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(); }