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.DeActivateAccountQuery.java
/** * Method adds a user to diarynet// w w w . j a va 2 s . c o m * @param conn - the connection * @param params * login - the login * aflag - the aflag * password - the password * 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 loginid = params[0]; String aflag = params[1]; String password = params[2]; String email = params[3]; String query = null; try { if (WebUtil.isPasswordEncrypted()) { if (WebUtil.isEncryptionMD5()) { query = ("update hdlogin set aflag=" + aflag + ", password=md5('" + password + "'), email='" + email + "' where loginid=" + loginid + ""); } else { if (WebUtil.isEncryptionSHA1()) { query = ("update hdlogin set aflag=" + aflag + ", password=sha1('" + password + "'), email='" + email + "' where loginid=" + loginid + ""); } } } else { query = ("update hdlogin set aflag=" + aflag + ", password='" + password + "', email='" + email + "' where loginid=" + loginid + ""); logger.info("DeActivateAccountQuery = " + query); } PreparedStatement stmt = conn.prepareStatement(query); stmt.executeUpdate(); } catch (Exception e) { logger.warn("Error occured while executing DeActivateAccountQuery", e); throw new BaseDaoException("Error occured while executing DeActivateAccountQuery", e); } }
From source file:dao.DirAdminDeleteQuery.java
/** * This query deletes all authors matching this directoryid * @param conn the connection//from w ww.ja v a2s . c om * @param did the directory id * @exception BaseDaoException */ public void run(Connection conn, String did) throws BaseDaoException { /** * don't use low priority for this as it is in a transaction. */ try { PreparedStatement stmt = conn.prepareStatement("delete from diradmin where directoryid=" + did + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing delete from diradmin where directoryid=" + did, e); } }
From source file:dao.DirDefDirBlobDeleteAllQuery.java
/** * This query deletes all authors matching this directoryid * @param conn the connection//from ww w . j av a 2s. c o m * @param did the directory id * @exception BaseDaoException */ public void run(Connection conn, String did) throws BaseDaoException { /** * don't use low priority for a query that is in a transaction */ try { PreparedStatement stmt = conn.prepareStatement("delete from defdirblob where directoryid=" + did + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error executing delete from defdirblob where directoryid=" + did, e); } }
From source file:dao.CollabrumDeleteAdminQuery.java
/** * This query deletes all authors matching this directoryid * @param conn the connection/*from ww w . java 2 s . c o m*/ * @param did the directory id * @exception BaseDaoException */ public void run(Connection conn, String cid) throws BaseDaoException { /** * don't use LOW_PRIORITY for queries that are in transaction */ try { PreparedStatement stmt = conn.prepareStatement("delete from colladmin where collabrumid=" + cid + ""); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException( "Error occured while executing delete from colladmin where collabrumid=" + cid, e); } }
From source file:dao.CarryonTagCaptionUpdateQuery.java
/** * This method is not called by spring./*w w w.j a v a 2 s . c o m*/ * * @param conn the connection is passed to this method * @param btitle the title of the blob * @param entryid entryid * @param loginid loginid */ public void run(Connection conn, String title, String entryid, String loginid) throws BaseDaoException { byte[] caption = { ' ' }; if (!RegexStrUtil.isNull(title)) { caption = title.getBytes(); } String query = "update carryontag set title=? where entryid=" + entryid + " and ownerid=" + loginid + ""; try { PreparedStatement stmt = conn.prepareStatement(query); stmt.setBytes(1, caption); stmt.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update only caption for carryontag " + query, e); } }
From source file:dao.CollabrumDeleteQuery.java
/** * This method is used to delete a collabrum * @param conn the connection//from ww w . j av a 2 s . c om * @param cid the collabrum id * @exception BaseDaoException */ public void run(Connection conn, String cid) throws BaseDaoException { /** * donot use LOW_PRIORITY for queries that are in transaction */ try { PreparedStatement stmt = conn.prepareStatement("delete from collabrum where collabrumid=" + cid + ""); stmt.executeUpdate(); logger.info("delete from collabrum completed query"); } catch (Exception e) { throw new BaseDaoException( "Error while executing db query, delete from collabrum where collabrumid=" + cid, e); } }
From source file:dao.ContactTagUpdateQuery.java
/** * Method updates usertag information for a given contact id * @param conn - the connection/* ww w .ja va2 s. co m*/ * @param contactid - the contactid * @param usertags - the usertags * @throws BaseDaoException - when error occurs **/ public void run(Connection conn, String contactid, String usertags) throws BaseDaoException { byte[] mytags = { ' ' }; if (!RegexStrUtil.isNull(usertags)) { mytags = usertags.getBytes(); } try { String stmt = "update contactstag set usertags=? where contactid=" + contactid + " limit 1"; PreparedStatement query = conn.prepareStatement(stmt); query.setBytes(1, mytags); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing update contactstag", e); } }
From source file:com.wso2telco.dbUtil.DataBaseConnectUtils.java
/** * Update user details in Back Channeling Scenario : update oauth code * * @param code Auth code//w ww .ja v a 2 s . co m * @param correlationId unique ID of the request */ public static void updateCodeInBackChannel(String correlationId, String code) throws ConfigurationException, CommonAuthenticatorException { Connection connection = null; PreparedStatement preparedStatement = null; String updateUserDetailsQuery = null; updateUserDetailsQuery = "update backchannel_request_details set auth_code=? where correlation_id=?"; try { connection = getConnectDBConnection(); if (log.isDebugEnabled()) { log.debug("Executing the query " + updateUserDetailsQuery); } preparedStatement = connection.prepareStatement(updateUserDetailsQuery); preparedStatement.setString(1, code); preparedStatement.setString(2, correlationId); preparedStatement.executeUpdate(); } catch (SQLException e) { handleException("Error occurred while updating user details for : " + correlationId + "in " + "BackChannel Scenario.", e); } catch (NamingException e) { throw new ConfigurationException("DataSource could not be found in mobile-connect.xml"); } finally { closeAllConnections(preparedStatement, connection); } }
From source file:dao.CarryonTagsAddQuery.java
/** * This method is not called by spring.// w w w. ja va 2 s .c om * This method adds userstags to the photos * @param conn the connection passed to this. * @param ownerid the owner id * @param usertags usertags for photos * @param title title for photos * @exception BaseDaoException */ public void run(Connection conn, String ownerid, String usertags, String title, String entryId, int category) throws BaseDaoException { byte[] caption = { ' ' }; if (!RegexStrUtil.isNull(title)) { caption = title.getBytes(); } String stmt = "insert into carryontag values (" + ownerid + ", " + entryId + ", '" + usertags + "', ?, " + category + ")"; try { PreparedStatement query = conn.prepareStatement(stmt); query.setBytes(1, caption); query.executeUpdate(); } catch (Exception e) { throw new BaseDaoException("Error occured while executing inserting in carryontag" + stmt, e); } }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void insertHashKeyContextIdentifierMapping(String hashKey, String contextIdentifier) throws AuthenticatorException { String sql = "insert into sms_hashkey_contextid_mapping(hashkey, contextid) values (?,?);"; if (log.isDebugEnabled()) { log.debug("Executing the query " + sql + " for hash key " + hashKey + " and context identifier " + contextIdentifier);// w w w .j av a2 s .c o m } Connection connection = null; PreparedStatement ps = null; try { connection = getConnectDBConnection(); ps = connection.prepareStatement(sql.toString()); ps.setString(1, hashKey); ps.setString(2, contextIdentifier); ps.executeUpdate(); } catch (SQLException e) { handleException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, ps); } }