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:org.trustedanalytics.datasetpublisher.service.HiveService.java
private void execute(String sql, JwtToken userIdentity) { LOGGER.info("Execute: {}", sql); try (Connection connection = hiveClient.getConnection(userIdentity)) { Statement stm = connection.createStatement(); stm.executeUpdate(sql); } catch (InterruptedException | IOException | LoginException | SQLException | URISyntaxException e) { LOGGER.error(String.format("Can't execute query %s", sql), e); throw Throwables.propagate(e); }//from w w w. j a v a2 s . c om }
From source file:db.IitbInfo.java
public void createIndexes(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate(CREATE_INDEX_SQL); }
From source file:db.IitbInfo.java
public void clearTable(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate(CLEAR_TABLE_SQL); }
From source file:db.IitbInfo.java
public void createTable(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate(DROP_TABLE_SQL); stmt.executeUpdate(CREATE_TABLE_SQL); }
From source file:com.trackplus.dao.DAOFactory.java
public void executeUpdateStatement(String sqlStatement) { Connection db = null;/*from w w w . j ava 2 s . c o m*/ try { //get the database name from any peer db = Torque.getConnection(BaseTWorkItemPeer.DATABASE_NAME); // it's the same name for all tables here, so we don't care Statement stmt; stmt = db.createStatement(); stmt.executeUpdate(sqlStatement); } catch (TorqueException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } catch (SQLException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } finally { Torque.closeConnection(db); } }
From source file:ems.util.DataHandler.java
public static boolean updateVoterStatus(ObservableList<MyModelSimpleStringProperty> list, String status) { String sqlQuery;// www.ja v a2s .c o m Connection con = getConnection(); Statement s = null; try { for (MyModelSimpleStringProperty list1 : list) { if (list1.isSelected()) { sqlQuery = String.format(Q_U_VOTER_STATUS, status, list1.getObj1(), list1.getObj2()); log.info("sqlQuery:" + sqlQuery); s = con.createStatement(); int i = s.executeUpdate(sqlQuery); log.info("updateVoterDetails|" + i); } } return true; } catch (SQLException e) { log.error("updateVoterDetails: " + e.getMessage()); } finally { try { if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("updateVoterDetails: " + ex.getMessage()); } } return false; }
From source file:org.softdays.mandy.AbstractDbSetupTest.java
public void execute(final String sql) { try {/*from w w w. j ava 2s . co m*/ final Connection c = this.databaseTester.getConnection().getConnection(); final Statement s = c.createStatement(); s.executeUpdate(sql); s.close(); } catch (final Exception e) { Assert.fail(e.getMessage()); } }
From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java
/** * Deletes the data object./* www . ja va 2s .com*/ * @param doShowError whether to show the an error dialog * @return true is ok, false if not */ public static boolean delete(final int id, final int tableId, final boolean doShowError) { errMsg = null; DBTableInfo ti = DBTableIdMgr.getInstance().getInfoById(tableId); Connection connection = DBConnection.getInstance().createConnection(); Statement stmt = null; try { stmt = connection.createStatement(); int numRecs = stmt .executeUpdate("DELETE FROM " + ti.getName() + " WHERE " + ti.getIdColumnName() + " = " + id); if (numRecs != 1) { // TODO need error message return false; } } catch (SQLException ex) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex); ex.printStackTrace(); errMsg = ex.toString(); try { connection.rollback(); } catch (SQLException ex2) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex2); ex.printStackTrace(); } return false; } finally { try { if (stmt != null) { stmt.close(); } if (connection != null) { connection.close(); } } catch (SQLException ex) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex); ex.printStackTrace(); } } return true; }
From source file:com.linuxrouter.netcool.session.QueryUtils.java
public Boolean executeUpdate(String dbName, String sql) { Long start = System.currentTimeMillis(); try {//from ww w.j av a 2 s . co m //connection caching... Connection con = null; if (connectionMap.get(dbName) == null) { BasicDataSource ds = DbUtils.getSimpleDataSourceByName(dbName); con = ds.getConnection(); connectionMap.put(dbName, con); } else { con = connectionMap.get(dbName); } Statement st = con.createStatement(); st.executeUpdate(sql); st.close(); } catch (SQLException ex) { logger.error("Erro ao executar query:", ex); return false; } Long end = System.currentTimeMillis(); return true; }
From source file:cc.osint.graphd.db.SQLDB.java
public void update(String expression) throws Exception { log.info("update(" + expression + ")"); Statement st = null; st = conn.createStatement();//w ww .java 2 s . co m int i = st.executeUpdate(expression); if (i == -1) { log.info("db error: " + expression); throw new Exception("db error: " + expression); } st.close(); }