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.sql.EmailOut.java

/**
 * Deletes email entry based off of the ID
 *
 * @param id Integer - emailID from the database
 *//*from   ww w . j a va 2 s .  c o  m*/
public static void deleteEmailEntry(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOut WHERE id = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, id);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.nabla.wapp.server.database.Database.java

public static Integer addRecord(final Connection conn, final String sql, final Object... parameters)
        throws SQLException {
    final PreparedStatement stmt = StatementFormat.prepare(conn, Statement.RETURN_GENERATED_KEYS, sql,
            parameters);/*from  w  ww  .j av a 2s  .c om*/
    try {
        if (stmt.executeUpdate() != 1) {
            if (log.isErrorEnabled())
                log.error("failed to add record");
            return null;
        }
        final ResultSet rsKey = stmt.getGeneratedKeys();
        try {
            rsKey.next();
            return rsKey.getInt(1);
        } finally {
            rsKey.close();
        }
    } finally {
        stmt.close();
    }
}

From source file:com.sql.DocketNotification.java

/**
 * Delete item from docket notification based off of ID
 * /*  ww  w .  jav a2 s .c  o  m*/
 * @param id Integer
 */
public static void deleteEmailEntry(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM DocketNotifications WHERE id = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, id);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:Emporium.Controle.ContrVpne.java

public static boolean inserirVpne(String sql, String nomeBD) {
    Connection conn = Conexao.conectar(nomeBD);
    try {/*w ww  . j a v  a  2 s . c  o m*/
        PreparedStatement valores = conn.prepareStatement(sql);
        valores.executeUpdate();
        valores.close();
        return true;
    } catch (SQLException e) {
        Logger.getLogger(ContrPreVendaImporta.class.getName()).log(Level.WARNING, e.getMessage(), e);
        return false;
    } finally {
        Conexao.desconectar(conn);
    }
}

From source file:de.thejeterlp.bukkit.login.SQLAccount.java

protected static void updateAccount(Account a) throws SQLException {
    checkReflection();/*from w w  w.  j ava2 s .c om*/
    Validate.notNull(a, "a cannot be null!");

    PreparedStatement st = Login.getInstance().getDB().getPreparedStatement(
            "UPDATE `" + Statics.PASSWORD_TABLE + "` SET `password` = ? WHERE `userID` = ?;");
    st.setString(1, a.getPassword());
    st.setInt(2, a.getID());
    st.executeUpdate();
    Login.getInstance().getDB().closeStatement(st);
}

From source file:com.sql.EmailOutAttachment.java

/**
 * Deletes attachment based off of email ID
 * //from w  w  w.j  a  v  a 2  s.c  om
 * @param id Integer
 */
public static void deleteAttachmentsForEmail(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOutAttachment WHERE emailOutID = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, id);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sql.EmailOutInvites.java

/**
 * Deletes email out invite from database after sending.
 * /* w ww  .j  ava 2  s.  c o m*/
 * @param id Integer
 */
public static void deleteEmailEntry(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOutInvites WHERE id = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, id);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sapienter.jbilling.tools.ConvertToBinHexa.java

private static void updateCCRow(int id, String number, String name) throws SQLException {
    PreparedStatement stmt = connection
            .prepareStatement("UPDATE credit_card set cc_number = ?, name = ? where ID = ?");
    stmt.setString(1, number);/*from   w w  w  . j a  v a2 s  .c om*/
    stmt.setString(2, name);
    stmt.setInt(3, id);
    stmt.executeUpdate();
}

From source file:com.sql.EmailOutRelatedCase.java

/**
 * Deletes related case based off of email ID
 * /*  w  ww .  j a  v  a2 s  . com*/
 * @param emailOutId Integer
 */
public static void deleteEmailOutRelatedForEmail(int emailOutId) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOutRelatedCase WHERE emailOutID = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, emailOutId);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sql.ServerEmailControl.java

/**
 * Update completion time of current thread.
 * //from   w w  w .  ja  va  2s .c o m
 * @param column
 */
public static void updateCompletionTime(String column) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "UPDATE ServerEmailControl SET " + column + " = GETDATE() WHERE "
                + "id = (SELECT TOP 1 id FROM ServerEmailControl)";
        ps = conn.prepareStatement(sql);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(conn);
    }
}