Example usage for java.sql PreparedStatement executeUpdate

List of usage examples for java.sql PreparedStatement executeUpdate

Introduction

In this page you can find the example usage for java.sql PreparedStatement executeUpdate.

Prototype

int executeUpdate() throws SQLException;

Source Link

Document

Executes the SQL statement in this 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.

Usage

From source file:com.concursive.connect.web.modules.profile.utils.ProjectUtils.java

/**
 * Accepts a project for the given user/*from ww  w. j  av  a2s.co m*/
 *
 * @param db        Description of the Parameter
 * @param projectId Description of the Parameter
 * @param userId    Description of the Parameter
 * @throws SQLException Description of the Exception
 */
public static void accept(Connection db, int projectId, int userId) throws SQLException {
    PreparedStatement pst = db.prepareStatement("UPDATE project_team " + "SET status = ? "
            + "WHERE project_id = ? " + "AND user_id = ? " + "AND status = ? ");
    DatabaseUtils.setInt(pst, 1, TeamMember.STATUS_ADDED);
    pst.setInt(2, projectId);
    pst.setInt(3, userId);
    pst.setInt(4, TeamMember.STATUS_PENDING);
    pst.executeUpdate();
    pst.close();
    CacheUtils.invalidateValue(Constants.SYSTEM_PROJECT_CACHE, projectId);
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

static int saveRequestType(String msisdn, Integer requestType)
        throws SQLException, NamingException, AuthenticatorException {
    Connection connection = null;
    //        String sql = "insert into pendingussd (msisdn, requesttype) values (?,?)";
    String sql = "insert into pendingussd (msisdn, requesttype) values (?,?) ON DUPLICATE KEY UPDATE "
            + "requesttype=VALUES(requesttype)";
    try {/* w ww.  j av  a 2 s  .  c  o m*/
        connection = getConnectDBConnection();
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.setString(1, msisdn);
        ps.setInt(2, requestType);
        ps.executeUpdate();
        return 1;
    } catch (SQLException e) {
        log.error("Error while saving request type ", e);
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
    return -1;
}

From source file:Emporium.Controle.ContrDestinatarioImporta.java

public static int inserir(int idCliente, int idDepartamento, String nome, String cpf_cnpj, String empresa,
        String cep, String endereco, String numero, String complemento, String bairro, String cidade, String uf,
        String email, String celular, String pais, String nomeBD, String tags) {
    Connection conn = Conexao.conectar(nomeBD);
    String sql = "INSERT INTO cliente_destinatario (idCliente, nome, cpf_cnpj, empresa, cep, endereco, numero, complemento, bairro, cidade, uf, email, celular, pais, tags, idDepartamento) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    //System.out.println("inserir Destinatario -----------------\n"+sql+"\n---------------");

    try {/*from w w w  .  ja va  2s .c o  m*/
        PreparedStatement valores = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
        valores.setInt(1, idCliente);
        valores.setString(2, FormataString.removeSpecialChars(nome));
        valores.setString(3, cpf_cnpj);
        valores.setString(4, empresa);
        valores.setString(5, cep);
        valores.setString(6, FormataString.removeSpecialChars(endereco));
        valores.setString(7, numero);
        valores.setString(8, complemento);
        valores.setString(9, bairro);
        valores.setString(10, cidade);
        valores.setString(11, uf);
        valores.setString(12, email);
        valores.setString(13, celular);
        valores.setString(14, pais);
        valores.setString(15, tags);
        valores.setInt(16, idDepartamento);
        valores.executeUpdate();
        int autoIncrementKey = 0;
        ResultSet rs = valores.getGeneratedKeys();
        if (rs.next()) {
            autoIncrementKey = rs.getInt(1);
        }
        valores.close();
        return autoIncrementKey;
    } catch (SQLException e) {
        //System.out.println("ERRO > "+e);
        ContrErroLog.inserir("HOITO - ContrPreVendaDest.inserir", "SQLException", sql, e.toString());
        return 0;
    } finally {
        Conexao.desconectar(conn);
    }
}

From source file:FacultyAdvisement.StudentRepository.java

public static void adminUpdate(DataSource ds, Student student, String oldUsername) throws SQLException {
    Connection conn = ds.getConnection();
    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }//from  w  ww  .j  a v  a2 s .  c o  m
    try {

        PreparedStatement ps;
        ps = conn.prepareStatement(
                "Update STUDENT set EMAIL=?, FIRSTNAME=?, LASTNAME=?, MAJORCODE=?, PHONE=?, ADVISED=? where STUID=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, student.getFirstName());
        ps.setString(3, student.getLastName());
        ps.setString(4, student.getMajorCode());
        ps.setString(5, student.getPhoneNumber());
        if (student.isAdvised()) {
            ps.setString(6, "true");
        } else {
            ps.setString(6, "false");
        }
        ps.setString(7, student.getId());
        ps.executeUpdate();

        ps = conn.prepareStatement("Update USERTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        ps = conn.prepareStatement("Update GROUPTABLE set USERNAME=? where USERNAME=?");
        ps.setString(1, student.getUsername());
        ps.setString(2, oldUsername);
        ps.executeUpdate();

        if (student.isResetPassword()) {
            String newPassword = UUID.randomUUID().toString();
            String encryptedPassword = SHA256Encrypt.encrypt(newPassword);
            ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?");
            ps.setString(1, encryptedPassword);
            ps.setString(2, student.getUsername());
            ps.executeUpdate();

            Email email = new HtmlEmail();
            email.setHostName("smtp.googlemail.com");
            email.setSmtpPort(465);
            email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234"));
            email.setSSLOnConnect(true);
            email.setFrom("uco.faculty.advisement@gmail.com");
            email.setSubject("UCO Faculty Advisement Password Change");
            email.setMsg("<font size=\"3\">An admin has resetted your password, your new password is \""
                    + newPassword + "\"." + "\n<p align=\"center\">UCO Faculty Advisement</p></font>");
            email.addTo(student.getUsername());
            email.send();

        }

    } catch (EmailException ex) {
        Logger.getLogger(StudentRepository.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        conn.close();
    }

    //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info
}

From source file:dao.ContactDeleteAllMemberQuery.java

public void run(Connection conn, String ownerid) throws BaseDaoException {

    String stmt = "delete LOW_PRIORITY from membercontacts where ownerid=" + ownerid + "";
    try {//from  ww  w .ja  v  a2 s .c  o  m
        PreparedStatement query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing membercontacts deletequery" + stmt, e);
    }
}

From source file:dao.ContactDeleteAllShareQuery.java

public void run(Connection conn, String loginid) throws BaseDaoException {

    String stmt = "delete LOW_PRIORITY from sharecontact where loginid=" + loginid + "";
    try {/*from w  w  w.  ja  va 2  s  . c o  m*/
        PreparedStatement query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing sharecontacts deletequery" + stmt, e);
    }
}

From source file:dao.ContactDeleteShareByIdQuery.java

public void run(Connection conn, String contactid) throws BaseDaoException {

    String stmt = "delete LOW_PRIORITY from sharecontact where contactid=" + contactid + "";
    try {//from w  w  w  .  j a va  2  s  .c  o m
        PreparedStatement query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing sharecontacts deletequery" + stmt, e);
    }
}

From source file:dao.ContactDeleteShareQuery.java

public void run(Connection conn, String contactid, String destid) throws BaseDaoException {

    String stmt = "delete LOW_PRIORITY from sharecontact where contactid=" + contactid + " and destid=" + destid
            + " limit 1";

    try {/*from w w w.java  2  s  .  com*/
        PreparedStatement query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing sharecontacts deletequery" + stmt, e);
    }
}

From source file:dao.UserTrafficDeleteQuery.java

/**
 *   This method deletes usertraffic information for this member
 *   @param conn - the connection/*from   w  w  w.  j  av  a 2  s  . c  o m*/
 *   @param loginid - the loginid
 *   @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String loginid) throws BaseDaoException {
    try {
        String query = "delete LOW_PRIORITY from usertraffic where memberid=" + loginid + "";
        PreparedStatement stmt = conn.prepareStatement(query);
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing usertraffic query ", e);
    }
}

From source file:dao.PblogMessageDeleteMidQuery.java

/**
 * Deletes a pblog message//  www  .j  av a 2 s  . c o  m
 * @param conn the connection
 * @param midStr the mid
 * @exception BaseDaoException
 */
public void run(Connection conn, String midStr) throws BaseDaoException {
    try {
        String query = "delete LOW_PRIORITY from pblogmessages where mid=" + midStr + "";
        PreparedStatement stmt = conn.prepareStatement(query);
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error in query, delete from pblogmessages where mid=" + midStr, e);
    }
}