List of usage examples for java.sql PreparedStatement executeUpdate
int executeUpdate() throws SQLException;
PreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or DELETE
; or an SQL statement that returns nothing, such as a DDL statement. From source file:de.bley.word.filewriter.WriterJdbc.java
/** * Ueberschreibt eine Datenbanktabelle.// www. ja v a2 s. co m * * @param filepath Ungenutzer Parameter des Interfaces. * @param text Inhalt, womit die Tabelle ueberschrieben werden soll. * */ @Override public void overwriteFile(String filepath, String text) { //Falsche implementation!!! Connection connection = JdbcConnection.getInstance().connect(); writeInFile(filepath, text, true); if (connection != null) { try { PreparedStatement ps = connection.prepareStatement("TRUNCATE TABLE APP.MYTABLE"); ps.executeUpdate(); for (String line : text.split(System.getProperty("line.separator"))) { ps = connection.prepareStatement("INSERT INTO APP.MYTABLE (DATA) VALUES (?)"); ps.setString(1, line); ps.executeUpdate(); } connection.close(); } catch (SQLException ex) { log.debug("execute of Query (remove value)", ex); } } }
From source file:org.apache.lucene.store.jdbc.handler.ActualDeleteFileEntryHandler.java
public void deleteFile(final String name) throws IOException { jdbcTemplate.execute(table.sqlDeleteByName(), new PreparedStatementCallback() { @Override//from w ww . ja va2 s . c o m public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setFetchSize(1); ps.setString(1, name); return ps.executeUpdate(); } }); }
From source file:dao.CollBlockDeleteQuery.java
/** * This method deletes the user from a blocked collabrum * @param conn - the connection/*w w w . jav a 2 s. c o m*/ * @param collabrumid - the collabrumid * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String collabrumid, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete from collblock where collabrumid=" + collabrumid + " and loginid='" + loginid + "'"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing collblock query ", e); } }
From source file:dao.PblogTagDeleteOneQuery.java
/** * This method deletes profile of the user * @param conn - the connection/*www .jav a2s.co m*/ * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String loginid, String tid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete LOW_PRIORITY from pblogtags where ownerid=" + loginid + " and tid=" + tid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing pblog tag delete query one loginid=" + loginid + " tid= " + tid, e); throw new BaseDaoException("Error occured while executing pblog tag delete one query ", e); } }
From source file:com.sf.ddao.ops.InsertAndGetGeneratedKeySqlOperation.java
public boolean execute(Context context) throws Exception { try {/*from w w w. j ava 2 s . c o m*/ final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class); PreparedStatement preparedStatement = statementFactory.createStatement(context, true); Object res = null; preparedStatement.executeUpdate(); ResultSet resultSet = preparedStatement.getGeneratedKeys(); if (resultSet.next()) { if (method.getReturnType() == Integer.TYPE || method.getReturnType() == Integer.class) { res = resultSet.getInt(1); } else if (method.getReturnType() == Long.TYPE || method.getReturnType() == Long.class) { res = resultSet.getLong(1); } else if (method.getReturnType() == BigDecimal.class) { res = resultSet.getBigDecimal(1); } } resultSet.close(); preparedStatement.close(); callCtx.setLastReturn(res); return CONTINUE_PROCESSING; } catch (Exception t) { throw new DaoException("Failed to execute sql operation for " + method, t); } }
From source file:dao.DirectoryDeleteAutoAuthorQuery.java
/** * This query deletes an author (only one) matching this directoryid and ownerid * @param conn the connection/*from w w w. j av a2 s.c o m*/ * @param did the directory id * @param ownerid the owner id * @exception BaseDaoException */ public void run(Connection conn, String did, String ownerid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete from diradmin where directoryid=" + did + " and ownerid=" + ownerid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing delete from diradmin where directoryid=" + did, e); } }
From source file:dao.FriendDeleteQuery.java
/** * This method deletes profile of the user * @param conn - the connection/*from w ww . ja v a2 s. c om*/ * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete LOW_PRIORITY from hdfriends where loginid=" + loginid + " or friendid=" + loginid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing hdfriends query ", e); } }
From source file:dao.ShareuserDeleteQuery.java
/** * This method deletes a user from list of shared users for this login * @param conn - the connection//w w w . ja v a2s . c o m * @param loginId - the login id * @param destid - the destination id **/ public void run(Connection conn, String loginid, String destid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete LOW_PRIORITY from shareuser where loginid=" + loginid + " and destid=" + destid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing db query ", e); } }
From source file:de.static_interface.reallifeplugin.module.corporation.database.table.CorpsTable.java
@Override public void create() throws SQLException { String sql;// w w w .ja v a 2 s. co m switch (db.getType()) { case H2: sql = "CREATE TABLE IF NOT EXISTS " + getName() + " (" + "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY," + "balance DOUBLE NOT NULL," + "base_id VARCHAR(255) NOT NULL," + "base_world VARCHAR(255) NOT NULL," + "ceo_uuid VARCHAR(36) NOT NULL UNIQUE KEY," + "corp_name VARCHAR(255) NOT NULL UNIQUE KEY," + "isdeleted TINYINT(0) NOT NULL," + "tag VARCHAR(5) UNIQUE KEY," + "time BIGINT NOT NULL" + ");"; break; case MYSQL: default: sql = "CREATE TABLE IF NOT EXISTS `" + getName() + "` (" + "`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY," + "`balance` DOUBLE NOT NULL," + "`base_id` VARCHAR(255) NOT NULL," + "`base_world` VARCHAR(255) NOT NULL," + "`ceo_uuid` VARCHAR(36) NOT NULL UNIQUE KEY," + "`corp_name` VARCHAR(255) NOT NULL UNIQUE KEY, " + "`isdeleted` TINYINT(0) NOT NULL," + "`tag` VARCHAR(5) UNIQUE KEY," + "`time` BIGINT NOT NULL" + ");"; break; } PreparedStatement statement = db.getConnection().prepareStatement(sql); statement.executeUpdate(); statement.close(); }
From source file:dao.PblogTopicNpDeleteQuery.java
/** * This method deletes profile of the user * @param conn - the connection/*from w w w . ja v a 2s. c o m*/ * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String loginid, String tid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete LOW_PRIORITY from pblogtopics_np where pblogid=" + loginid + " and tid=" + tid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error, pblogtopics_np delete query one loginid=" + loginid + " tid= " + tid, e); throw new BaseDaoException("Error deleting query pblogtopics_np ", e); } }