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:dao.ShareuserDeleteAllQuery.java
/** * This method deletes any entries that match with this user. (shared user or shared by other with this user) * @param conn - the connection/*from ww w .j av a 2 s.c o m*/ * @param loginId - the login id **/ public void run(Connection conn, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "delete LOW_PRIORITY from shareuser where loginid=" + loginid + " or destid=" + loginid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing db query ", e); } }
From source file:dao.DirCopyUpdateQuery.java
/** * This method updates dircopy//from w w w .j av a2 s.c om * This method can be invoked only either the admins or the authors of this directory * @param conn the connection * @param directoryid the directory id * @param loginid the id of the owner * @exception BaseDaoException */ public void run(Connection conn, String directoryId, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "update dircopy set directoryid=" + directoryId + " where loginid=" + loginid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error executing db query, update dircopy loginid=" + loginid, e); } }
From source file:dao.DirectoryBlockDeleteQuery.java
/** * This method deletes a user from blocked directory * @param conn - the connection/*from www . j a va 2 s .c o m*/ * @param directoryid - the directoryid * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String directoryid, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement("delete from dirblock where directoryid=" + directoryid + " and loginid=" + loginid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing dirblock query ", e); } }
From source file:dao.DirMoveUpdateQuery.java
/** * This method updates dirmove/* w ww. j a va 2 s. co m*/ * This method can be invoked only either the admins or the authors of this directory * @param conn the connection * @param directoryid the directory id * @param ownerid the id of the owner * @exception BaseDaoException */ public void run(Connection conn, String directoryId, String loginid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement( "update dirmove set directoryid=" + directoryId + " where loginid=" + loginid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error executing db query, update dirmove where loginid=" + loginid, e); } }
From source file:net.paoding.rose.jade.provider.jdbctemplate.PreparedStatementCallbackReturnId.java
@Override public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { if (setter != null) { setter.setValues(ps);// w w w .jav a2 s . c o m } ps.executeUpdate(); ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { RowMapperResultSetExtractor extractor = new RowMapperResultSetExtractor( new SingleColumnRowMapper(Number.class), 1); return DataAccessUtils.requiredSingleResult((List<?>) extractor.extractData(keys)); } finally { JdbcUtils.closeResultSet(keys); } } return null; }
From source file:dao.DirMoveDeleteQuery.java
/** * This method deletes directory//from www . j av a 2 s .co m * This method can be invoked only either the admins or the authors of this directory * @param conn the connection * @param cid the category id * @param ownerid the id of the owner * @exception BaseDaoException */ public void run(Connection conn, String directoryId, String loginid) throws BaseDaoException { try { // PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from dirmove where directoryid="+directoryId+" and loginid="+loginid+" limit 1"); PreparedStatement stmt = conn.prepareStatement("delete from dirmove where directoryid=" + directoryId + " and loginid=" + loginid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error executing db query, delete from dirmove where directoryid=" + directoryId, e); } }
From source file:genepi.db.h2.H2Connector.java
public void executeSQL(InputStream is) throws SQLException, IOException, URISyntaxException { String sqlContent = readFileAsString(is); if (!sqlContent.isEmpty()) { Connection connection = dataSource.getConnection(); PreparedStatement ps = connection.prepareStatement(sqlContent); ps.executeUpdate(); connection.close();//from w ww . ja v a 2 s .c om } }
From source file:dao.DirWebsiteDeleteQuery.java
/** * This functions deletes website for a platz * @param conn the connection// w w w . j a v a 2s.c o m * @param entryid the id of the entry * @param ownerid the id of the owner * @exception BaseDaoException */ public void run(Connection conn, String entryid, String ownerid) throws BaseDaoException { try { PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from dirwebsites where entryid=" + entryid + " and ownerid=" + ownerid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing db query, delete from dirwebsites where entryid=" + entryid + "ownerid=" + ownerid, e); } }
From source file:fll.db.NonNumericNominees.java
/** * Add a set of nominees to the database. If the nominee already exsts, there * is no error.//www . j a v a 2 s. c o m * * @throws SQLException */ public static void addNominees(final Connection connection, final int tournamentId, final String category, final Set<Integer> teamNumbers) throws SQLException { PreparedStatement check = null; ResultSet checkResult = null; PreparedStatement insert = null; final boolean autoCommit = connection.getAutoCommit(); try { connection.setAutoCommit(false); check = connection.prepareStatement("SELECT team_number FROM non_numeric_nominees" // + " WHERE tournament = ?" // + " AND category = ?" // + " AND team_number = ?"); check.setInt(1, tournamentId); check.setString(2, category); insert = connection.prepareStatement("INSERT INTO non_numeric_nominees" // + " (tournament, category, team_number) VALUES(?, ?, ?)"); insert.setInt(1, tournamentId); insert.setString(2, category); for (final int teamNumber : teamNumbers) { check.setInt(3, teamNumber); insert.setInt(3, teamNumber); checkResult = check.executeQuery(); if (!checkResult.next()) { insert.executeUpdate(); } } connection.commit(); } finally { connection.setAutoCommit(autoCommit); SQLFunctions.close(checkResult); SQLFunctions.close(check); SQLFunctions.close(insert); } }
From source file:dao.PendingfriendsDeleteQuery.java
/** * This method deletes profile of the user * @param conn - the connection/*ww w. ja v a 2 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 pendingfriends where loginid=" + loginid + " or destloginid=" + loginid + ""); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing pendingfriends query ", e); throw new BaseDaoException("Error occured while executing pendingfriends query ", e); } }