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.CollabrumAddAdminQuery.java
/** * This method is not called by spring./*from ww w .ja va 2s. co m*/ * * @param conn the connection passed to this. * @param collabrumid the collabrum id * @param parentid the parent id (directory id) that this collabrum belongs to * @exception BaseDaoException */ public void run(Connection conn, String collabrumid, String loginid) throws BaseDaoException { PreparedStatement stmt = null; String query = null; try { query = "insert into colladmin values (0, " + collabrumid + ", " + loginid + ")"; stmt = conn.prepareStatement(query); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error executing CollabrumAddAdminQuery " + query, e); } }
From source file:dao.CollModeratorDeleteQuery.java
/** * This method deletes a moderator //from ww w . j a va 2 s .c o m * @param conn- the connection * @param collabrumId - the collabrumid * @param loginid - the loginid * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String collabrumid, String loginid) throws BaseDaoException { PreparedStatement stmt = null; try { stmt = conn.prepareStatement("delete LOW_PRIORITY from colladmin where collabrumid=" + collabrumid + " and loginid=" + loginid + " limit 1"); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing db query " + stmt, e); throw new BaseDaoException("Error occured while executing db query " + stmt, e); } }
From source file:com.laxser.blitz.lama.provider.jdbc.PreparedStatementCallbackReturnId.java
@Override public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { if (setter != null) { setter.setValues(ps);/*from www . j a va 2 s . co m*/ } int updated = ps.executeUpdate(); if (updated == 0) { if (returnType.isArray()) { return Array.newInstance(wrappedIdType, 0); } else { return defaultValueOf(wrappedIdType); } } ResultSet keys = ps.getGeneratedKeys(); if (keys != null) { try { Object ret = null; if (returnType.isArray()) { keys.last(); int length = keys.getRow(); keys.beforeFirst(); ret = Array.newInstance(wrappedIdType, length); } for (int i = 0; keys.next(); i++) { Object value = mapper.mapRow(keys, i); if (value == null && idType.isPrimitive()) { // ?primitive??null?? value = defaultValueOf(wrappedIdType); } if (ret != null) { Array.set(ret, i + 1, value); } else { ret = value; break; } } return ret; } finally { JdbcUtils.closeResultSet(keys); } } else { if (returnType.isArray()) { return Array.newInstance(wrappedIdType, 0); } else { return defaultValueOf(wrappedIdType); } } }
From source file:dao.CobrandSiteAddVhostQuery.java
/** * This method is not called by spring.//from w ww .j a v a 2s. co m * * @param conn the connection passed to this. * @param vhost the vhost * @param header the header * @param footer the footer * @param vroot the vroot * @exception BaseDaoException */ public void run(Connection conn, String vhost, String vroot) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "insert into vhosts values(0, '" + vhost + "', '" + vroot + "', '', '')"; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing cobrandsite inserting query, query = " + stmt, e); } }
From source file:dao.PasswordUpdateQuery.java
/** * Method adds a user to diarynet//from w w w . ja v a 2 s . co m * @param conn - the connection * @param params * login - the login * fname - the fname * lname - the lname * mname - the mname * email - the email * @throws BaseDaoException - when error occurs **/ //public void run(Connection conn, String login, String fname, String lname, //String mname, String email, String password, int aCode, String aFlag ) throws BaseDaoException { public void run(Connection conn, String[] params) throws BaseDaoException { String password = params[0]; String login = params[1]; if (RegexStrUtil.isNull(password) || RegexStrUtil.isNull(login)) { throw new BaseDaoException("params are null"); } try { if (WebUtil.isPasswordEncrypted()) { if (WebUtil.isEncryptionMD5()) { PreparedStatement stmt = conn.prepareStatement( "update hdlogin set password=md5('" + password + "') where login='" + login + "'"); stmt.executeUpdate(); } else { if (WebUtil.isEncryptionSHA1()) { PreparedStatement stmt = conn.prepareStatement( "update hdlogin set password=sha1('" + password + "') where login='" + login + "'"); stmt.executeUpdate(); } } } else { PreparedStatement stmt = conn.prepareStatement( "update hdlogin set password='" + password + "' where login='" + login + "'"); stmt.executeUpdate(); String query = ("update hdlogin set password='" + password + "' where login='" + login + "'"); logger.info("PasswordUpdateQuery = " + query); } } catch (Exception e) { logger.warn("Error occured while executing PasswordUpdateQuery", e); throw new BaseDaoException("Error occured while executing PasswordUpdateQuery", e); } }
From source file:dao.CobrandSiteUpdateQuery.java
/** * This method is not called by spring./*from w w w . j a v a 2s . co m*/ * * @param conn the connection passed to this. * @param vhostid the vhostid * @param footer the footer * @exception BaseDaoException */ public void run(Connection conn, String vhostid, String vroot) throws BaseDaoException { PreparedStatement query = null; String stmt = null; try { stmt = "update vhosts set vroot=" + vroot + " where entryid=" + vhostid + " limit 1"; query = conn.prepareStatement(stmt); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing vhosts updating query, query = " + stmt, e); } }
From source file:io.muic.ooc.webapp.service.UserService.java
public void deleteUser(Connection conn, String id) { String query = "delete from account where id = ?"; try {/*from w ww . j a va2 s . c o m*/ PreparedStatement preparedStatement = conn.prepareStatement(query); preparedStatement.setString(1, id); // do update preparedStatement.executeUpdate(); } catch (SQLException e) { System.out.println("Can't delete user"); } }
From source file:iddb.web.security.dao.SessionDAO.java
public void delete(String key) { String sql;// www .j a v a2 s . c om sql = "delete from user_session where id = ?"; Connection conn = null; try { conn = ConnectionFactory.getMasterConnection(); PreparedStatement st = conn.prepareStatement(sql); st.setString(1, key); int r = st.executeUpdate(); log.debug("Removed {} sessions", Integer.toString(r)); } catch (SQLException e) { log.error("delete", e); } catch (IOException e) { log.error("delete", e); } finally { try { if (conn != null) conn.close(); } catch (Exception e) { } } }
From source file:com.imagelake.control.KeyWordsDAOImp.java
@Override public boolean removeKeyWord(int key_word_id) { boolean ok = false; try {/* w w w . java 2 s. c o m*/ String sql = "DELETE FROM key_words WHERE key_words_id=?"; Connection con = DBFactory.getConnection(); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, key_word_id); int i = ps.executeUpdate(); if (i > 0) { ok = true; } else { ok = false; } } catch (Exception e) { e.printStackTrace(); } return ok; }
From source file:dao.DirPasteQuery.java
/** * Method updates directory path information * @param conn - the connection//from www . j av a 2 s . co m * @param directoryId - the directory Id * @param dirPath - the directory path * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String directoryId, String dirpath) throws BaseDaoException { try { byte[] path = { ' ' }; if (!RegexStrUtil.isNull(dirpath)) { path = dirpath.getBytes(); } PreparedStatement query = null; String stmt = "update directory set dirpath=? where directoryId=" + directoryId + ""; query = conn.prepareStatement(stmt); query.setBytes(1, path); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update directory path ", e); } }