Example usage for java.sql PreparedStatement setInt

List of usage examples for java.sql PreparedStatement setInt

Introduction

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

Prototype

void setInt(int parameterIndex, int x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java int value.

Usage

From source file:fll.JudgeInformation.java

/**
 * Get all judges stored for this tournament.
 * /*from  w w w.  j a v a 2 s.  c  o m*/
 * @param connection the database
 * @param tournament tournament ID
 * @return the judges
 * @throws SQLException
 */
public static Collection<JudgeInformation> getJudges(final Connection connection, final int tournament)
        throws SQLException {
    Collection<JudgeInformation> judges = new LinkedList<JudgeInformation>();

    ResultSet rs = null;
    PreparedStatement stmt = null;
    try {
        stmt = connection.prepareStatement("SELECT id, category, station FROM Judges WHERE Tournament = ?");
        stmt.setInt(1, tournament);
        rs = stmt.executeQuery();
        while (rs.next()) {
            final String id = rs.getString(1);
            final String category = rs.getString(2);
            final String station = rs.getString(3);
            final JudgeInformation judge = new JudgeInformation(id, category, station);
            judges.add(judge);
        }
    } finally {
        SQLFunctions.close(rs);
        SQLFunctions.close(stmt);
    }

    return judges;
}

From source file:com.chaosinmotion.securechat.server.commands.RemoveDevice.java

public static boolean processRequest(Login.UserInfo userinfo, JSONObject requestParams)
        throws ClassNotFoundException, SQLException, IOException {
    String deviceid = requestParams.optString("deviceid");

    /*//w  w  w .  jav  a  2 s. c  o m
     * Delete device. We only delete if it is also ours.
     */
    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        c = Database.get();
        ps = c.prepareStatement("DELETE FROM Devices " + "WHERE userid = ? AND deviceuuid = ?");
        ps.setInt(1, userinfo.getUserID());
        ps.setString(2, deviceid);
        ps.execute();

        return true;
    } finally {
        if (rs != null)
            rs.close();
        if (ps != null)
            ps.close();
        if (c != null)
            c.close();
    }
}

From source file:com.sql.EmailOut.java

/**
 * Deletes email entry based off of the ID
 *
 * @param id Integer - emailID from the database
 *///from   w  w  w. j av  a2s  . 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.sql.DocketNotification.java

/**
 * Delete item from docket notification based off of ID
 * //from   w w w . j  a v  a  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 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:de.thejeterlp.bukkit.login.SQLAccount.java

protected static void updateAccount(Account a) throws SQLException {
    checkReflection();/*from  w w  w .  j  a v  a2s  .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
 * /* ww w. j  a  va2s  . co  m*/
 * @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.EmailAttachment.java

/**
 * Insert attachement into received email attachment database table.
 * /*from w  w  w .  j  a  v a  2 s.c o m*/
 * @param EmailID Integer
 * @param fileName String
 */
public static void insertEmailAttachment(int EmailID, String fileName) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "INSERT INTO EmailAttachment (" + "emailID, " + "fileName " + ") VALUES (" + "?, " + "?)";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, EmailID);
        ps.setString(2, fileName);
        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.
 * //from w  w  w.  j  a  v a 2s. c om
 * @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.sql.EmailOutRelatedCase.java

/**
 * Deletes related case based off of email ID
 * /*from   ww  w .j  ava  2 s.  c  o  m*/
 * @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.concursive.connect.web.modules.activity.utils.ProjectHistoryUtils.java

public static int findNextPosition(Connection db, int projectHistoryId) throws SQLException {
    int position = 0;
    PreparedStatement pst = db.prepareStatement("SELECT max(position) AS position " + "FROM project_history "
            + "WHERE history_id = ? OR top_id = ? ");
    pst.setInt(1, projectHistoryId);
    pst.setInt(2, projectHistoryId);// w w  w .  j a  v  a 2  s.c o  m
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        position = rs.getInt("position");
    }
    rs.close();
    pst.close();
    return (position + 1);
}