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:at.becast.youploader.database.SQLite.java

public static void setPlaylistHidden(int id, String hidden) throws SQLException {
    PreparedStatement prest = null;
    String sql = "UPDATE `playlists` SET `shown`=? WHERE `id`=?";
    prest = c.prepareStatement(sql);// ww  w.  j  a va  2  s. c  om
    prest.setString(1, hidden);
    prest.setInt(2, id);
    prest.execute();
    prest.close();
}

From source file:at.becast.youploader.database.SQLite.java

public static Boolean updateUpload(int account, File file, Video data, String enddir, VideoMetadata metadata,
        int id) throws SQLException, IOException {
    PreparedStatement prest = null;
    String sql = "UPDATE `uploads` SET `account`=?, `file`=?, `lenght`=?, `enddir`=? WHERE `id`=?";
    prest = c.prepareStatement(sql);//ww  w  .j  a v a2 s .  c o m
    prest.setInt(1, account);
    prest.setString(2, file.getAbsolutePath());
    prest.setLong(3, file.length());
    prest.setString(4, enddir);
    prest.setInt(5, id);
    boolean res = prest.execute();
    prest.close();
    boolean upd = updateUploadData(data, metadata, id);
    return res && upd;
}

From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java

public static int queryObjectRatingValue(Connection db, int objectId, String table, String uniqueField)
        throws SQLException {
    int count = -1;
    PreparedStatement pst = db
            .prepareStatement("SELECT rating_value FROM " + table + " " + "WHERE " + uniqueField + " = ? ");
    pst.setInt(1, objectId);
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        count = rs.getInt("rating_value");
    }// w  w  w .  jav  a  2 s  .c  o m
    rs.close();
    pst.close();
    return count;
}

From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java

public static int queryUserRating(Connection db, int userId, int objectId, String table, String uniqueField)
        throws SQLException {
    int existingVote = -1;
    PreparedStatement pst = db.prepareStatement(
            "SELECT rating FROM " + table + "_rating WHERE " + uniqueField + " = ? AND enteredby = ? ");
    pst.setInt(1, objectId);
    pst.setInt(2, userId);/*w ww.  ja v a2  s.  c o  m*/
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        existingVote = rs.getInt("rating");
    }
    rs.close();
    pst.close();
    return existingVote;
}

From source file:fll.web.admin.UploadSubjectiveData.java

/**
 * Add any judges to the database that are referenced in the score file that
 * aren't already in the database./*from   w  ww  .  j a  va  2s.  c o  m*/
 */
private static void addMissingJudges(final Connection connection, final int tournamentId,
        final Document scoreDocument) throws SQLException {

    PreparedStatement insertJudge = null;
    try {
        insertJudge = connection
                .prepareStatement("INSERT INTO Judges (id, category, Tournament, station) VALUES (?, ?, ?, ?)");
        insertJudge.setInt(3, tournamentId);

        final Collection<JudgeInformation> currentJudges = JudgeInformation.getJudges(connection, tournamentId);

        final Element scoresElement = scoreDocument.getDocumentElement();

        for (final Element scoreCategoryNode : new NodelistElementCollectionAdapter(
                scoresElement.getChildNodes())) {
            final Element scoreCategoryElement = scoreCategoryNode; // "subjectiveCategory"
            final String categoryName = scoreCategoryElement.getAttribute("name");

            for (final Element scoreElement : new NodelistElementCollectionAdapter(
                    scoreCategoryElement.getElementsByTagName("score"))) {
                final String judgeId = scoreElement.getAttribute("judge");
                final String station = scoreElement.getAttribute("judging_station");
                final JudgeInformation judge = new JudgeInformation(judgeId, categoryName, station);
                if (!doesJudgeExist(currentJudges, judge)) {
                    // add judge
                    insertJudge.setString(1, judge.getId());
                    insertJudge.setString(2, judge.getCategory());
                    insertJudge.setString(4, judge.getGroup());
                    insertJudge.executeUpdate();

                    currentJudges.add(judge);
                }
            } // foreach score
        } // foreach category

    } finally {
        SQLFunctions.close(insertJudge);
    }

}

From source file:at.becast.youploader.database.SQLite.java

public static Boolean updateUploadProgress(int id, long progress) {
    PreparedStatement prest = null;
    String sql = "UPDATE `uploads` SET `uploaded`=? WHERE `id`=?";
    try {//from w w w.j a v  a  2 s .co  m
        prest = c.prepareStatement(sql);
        prest.setLong(1, progress);
        prest.setInt(2, id);
        boolean res = prest.execute();
        prest.close();
        return res;
    } catch (SQLException e) {
        LOG.error("Error updating upload progress", e);
        return false;
    }
}

From source file:fll.db.NonNumericNominees.java

/**
 * Add a set of nominees to the database. If the nominee already exsts, there
 * is no error.// w  ww .ja va  2  s.com
 * 
 * @throws SQLException
 */
public static void addNominees(final Connection connection, final int tournamentId, final String category,
        final Set<Integer> teamNumbers) throws SQLException {
    PreparedStatement check = null;
    ResultSet checkResult = null;
    PreparedStatement insert = null;
    final boolean autoCommit = connection.getAutoCommit();
    try {
        connection.setAutoCommit(false);

        check = connection.prepareStatement("SELECT team_number FROM non_numeric_nominees" //
                + " WHERE tournament = ?" //
                + "   AND category = ?" //
                + "   AND team_number = ?");
        check.setInt(1, tournamentId);
        check.setString(2, category);

        insert = connection.prepareStatement("INSERT INTO non_numeric_nominees" //
                + " (tournament, category, team_number) VALUES(?, ?, ?)");
        insert.setInt(1, tournamentId);
        insert.setString(2, category);

        for (final int teamNumber : teamNumbers) {
            check.setInt(3, teamNumber);
            insert.setInt(3, teamNumber);

            checkResult = check.executeQuery();
            if (!checkResult.next()) {
                insert.executeUpdate();
            }
        }

        connection.commit();
    } finally {
        connection.setAutoCommit(autoCommit);

        SQLFunctions.close(checkResult);
        SQLFunctions.close(check);
        SQLFunctions.close(insert);
    }
}

From source file:com.l2jfree.gameserver.network.L2Client.java

public static void deleteCharByObjId(int objid) {
    if (objid < 0)
        return;/*  ww  w  .  j a  v a  2s .  co  m*/

    Connection con = null;

    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement;

        for (ItemRelatedTable table : TableOptimizer.getItemRelatedTables()) {
            statement = con.prepareStatement(table.getDeleteQuery());
            statement.setInt(1, objid);
            statement.execute();
            statement.close();
        }

        for (CharacterRelatedTable table : TableOptimizer.getCharacterRelatedTables()) {
            statement = con.prepareStatement(table.getDeleteQuery());
            statement.setInt(1, objid);
            statement.execute();
            statement.close();
        }

        statement = con.prepareStatement("DELETE FROM items WHERE owner_id=?");
        statement.setInt(1, objid);
        statement.execute();
        statement.close();

        statement = con.prepareStatement("DELETE FROM characters WHERE charId=?");
        statement.setInt(1, objid);
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.error("Error deleting character.", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

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

public static boolean processRequest(Login.UserInfo userinfo, JSONObject requestParams)
        throws ClassNotFoundException, SQLException, IOException {
    String newPassword = requestParams.getString("password");
    String requestToken = requestParams.getString("token");

    /*// w ww . j  av  a2 s .  co m
     * Determine if the token matches for this user record. We are in the
     * unique situation of having a logged in user, but he doesn't know
     * his password. We also ignore any requests with an expired
     * token.
     */

    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        /*
         * Delete old requests
         */
        c = Database.get();
        ps = c.prepareStatement("DELETE FROM forgotpassword WHERE expires < LOCALTIMESTAMP");
        ps.execute();

        ps.close();
        ps = null;

        /*
         * Verify the token we passed back was correct
         */
        ps = c.prepareStatement(
                "SELECT token " + "FROM forgotpassword " + "WHERE userid = ? " + "AND token = ?");
        ps.setInt(1, userinfo.getUserID());
        ps.setString(2, requestToken);
        rs = ps.executeQuery();
        if (!rs.next())
            return false; // token does not exist or expired.

        rs.close();
        rs = null;
        ps.close();
        ps = null;

        /*
         * Step 2: Modify the password.
         */

        ps = c.prepareStatement("UPDATE Users SET password = ? WHERE userid = ?");
        ps.setString(1, newPassword);
        ps.setInt(2, userinfo.getUserID());
        ps.execute();

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

From source file:com.concursive.connect.web.modules.common.social.rating.dao.Rating.java

public static void deleteByProject(Connection db, int projectId, String table, String uniqueField)
        throws SQLException {
    PreparedStatement pst = db.prepareStatement("DELETE FROM " + table + "_rating " + "WHERE " + uniqueField
            + " IN (SELECT " + uniqueField + "FROM " + table + " WHERE project_id = ?)");
    pst.setInt(1, projectId);
    pst.execute();/*from  w  ww  .java2  s .  c  om*/
    pst.close();
}