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:com.concursive.connect.web.modules.wiki.utils.WikiUtils.java

public static HashMap<String, ImageInfo> buildImageInfo(Connection db, int projectId) throws SQLException {
    HashMap<String, ImageInfo> images = new HashMap<String, ImageInfo>();
    // Full size image
    PreparedStatement pst = db
            .prepareStatement("SELECT client_filename, filename, image_width, image_height, version "
                    + "FROM project_files " + "WHERE link_module_id = ? " + "AND link_item_id = ? ");
    pst.setInt(1, Constants.PROJECT_WIKI_FILES);
    pst.setInt(2, projectId);/*  www  .j  a  va  2  s . c om*/
    ResultSet rs = pst.executeQuery();
    while (rs.next()) {
        ImageInfo image = new ImageInfo(rs);
        images.put(image.getFilename(), image);
    }
    rs.close();
    pst.close();
    return images;
}

From source file:module.entities.NameFinder.DB.java

/**
 * Starts the activity log/*from ww  w  .  j a  va 2s .  c  om*/
 *
 * @param startTime - The start time of the crawling procedure
 * @return - The activity's log id
 * @throws java.sql.SQLException
 */
public static int LogRegexFinder(long startTime) throws SQLException {
    String insertLogSql = "INSERT INTO log.activities (module_id, start_date, end_date, status_id, message) VALUES (?,?,?,?,?)";
    PreparedStatement prepLogCrawlStatement = connection.prepareStatement(insertLogSql,
            Statement.RETURN_GENERATED_KEYS);
    prepLogCrawlStatement.setInt(1, 4);
    prepLogCrawlStatement.setTimestamp(2, new java.sql.Timestamp(startTime));
    prepLogCrawlStatement.setTimestamp(3, null);
    prepLogCrawlStatement.setInt(4, 1);
    prepLogCrawlStatement.setString(5, null);
    prepLogCrawlStatement.executeUpdate();
    ResultSet rsq = prepLogCrawlStatement.getGeneratedKeys();
    int crawlerId = 0;
    if (rsq.next()) {
        crawlerId = rsq.getInt(1);
    }
    prepLogCrawlStatement.close();
    return crawlerId;
}

From source file:module.entities.NameFinder.DB.java

public static void insertDemocracitConsultationMinister(TreeMap<Integer, String> consultationCountersign,
        TreeMap<Integer, String> consultationCounterrole) throws SQLException {
    try {//from  w  w w  . j  a va2 s . c o  m
        String sql = "INSERT INTO consultations_ner "
                + "(id,countersigned_name, countersigned_position) VALUES " + "(?,?,?)";
        PreparedStatement prepStatement = connection.prepareStatement(sql);
        for (int consId : consultationCountersign.keySet()) {
            prepStatement.setInt(1, consId);
            prepStatement.setString(2, consultationCountersign.get(consId));
            if (consultationCounterrole.get(consId) != null) {
                prepStatement.setString(3, consultationCounterrole.get(consId));
            } else {
                prepStatement.setString(3, "");
            }
            prepStatement.addBatch();
        }
        prepStatement.executeBatch();
        prepStatement.close();
    } catch (BatchUpdateException ex) {
        //            ex.printStackTrace();
        System.out.println(ex.getNextException());
    }
}

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

public static Boolean deleteUpload(int upload_id) {
    PreparedStatement prest = null;
    String sql = "DELETE FROM `uploads` WHERE `id`=?";
    try {/*from  w w  w . j  ava  2  s  .c  o  m*/
        prest = c.prepareStatement(sql);
        prest.setInt(1, upload_id);
        boolean res = prest.execute();
        prest.close();
        return res;
    } catch (SQLException e) {
        LOG.error("Error deleting upload", e);
        return false;
    }
}

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

public static void deletePlaylist(int id) {
    PreparedStatement prest = null;
    String sql = "DELETE FROM `playlists` WHERE `id`=?";
    try {/*  w  ww  .jav a 2s .  c om*/
        prest = c.prepareStatement(sql);
        prest.setInt(1, id);
        prest.close();
    } catch (SQLException e) {
        LOG.error("Error deleting Playlist ", e);
    }

}

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

public static Boolean deleteTemplate(int id) {
    PreparedStatement prest = null;
    String sql = "DELETE FROM `templates` WHERE `id`=?";
    try {//from w  w  w  . ja  va  2  s  . co  m
        prest = c.prepareStatement(sql);
        prest.setInt(1, id);
        boolean res = prest.execute();
        prest.close();
        return res;
    } catch (SQLException e) {
        LOG.error("Error deleting Template ", e);
        return false;
    }
}

From source file:module.entities.NameFinder.DB.java

/**
 * Update the activity log/*from   w w w.j a v  a2 s . c om*/
 *
 * @param endTime
 * @param status_id
 * @param regexerId
 * @param obj
 * @throws java.sql.SQLException
 */
public static void UpdateLogRegexFinder(long endTime, int regexerId, JSONObject obj) throws SQLException {
    String updateCrawlerStatusSql = "UPDATE log.activities SET " + "end_date = ?, status_id = ?, message = ?"
            + "WHERE id = ?";
    PreparedStatement prepUpdStatusSt = connection.prepareStatement(updateCrawlerStatusSql);
    prepUpdStatusSt.setTimestamp(1, new java.sql.Timestamp(endTime));
    prepUpdStatusSt.setInt(2, 2);
    prepUpdStatusSt.setString(3, obj.toJSONString());
    prepUpdStatusSt.setInt(4, regexerId);
    prepUpdStatusSt.executeUpdate();
    prepUpdStatusSt.close();
}

From source file:com.wso2telco.historylog.DbTracelog.java

/**
 * Log history./*from ww w.  j  av  a 2 s  . com*/
 *
 * @param Reqtype         the reqtype
 * @param isauthenticated the isauthenticated
 * @param application     the application
 * @param authUser        the auth user
 * @param authenticators  the authenticators
 * @param ipaddress       the ipaddress
 * @throws LogHistoryException the log history exception
 */
public static void LogHistory(String Reqtype, boolean isauthenticated, String application, String authUser,
        String authenticators, String ipaddress) throws LogHistoryException {
    Connection con = null;
    PreparedStatement pst = null;
    try {
        con = DbTracelog.getMobileDBConnection();

        String sql = "INSERT INTO sp_login_history (reqtype, application_id, authenticated_user, isauthenticated,"
                + " authenticators,ipaddress, created, created_date)" + " VALUES " + "(?, ?, ?, ?, ?, ?, ?, ?)";

        pst = con.prepareStatement(sql);

        pst.setString(1, Reqtype);
        pst.setString(2, application);
        pst.setString(3, authUser);
        pst.setInt(4, (isauthenticated ? 1 : 0));
        pst.setString(5, authenticators);
        pst.setString(6, ipaddress);
        pst.setString(7, "authUser");
        pst.setTimestamp(8, new java.sql.Timestamp(new java.util.Date().getTime()));
        pst.executeUpdate();

    } catch (SQLException e) {
        handleException(
                "Error occured while Login SP LogHistory: " + application + " Service Provider: " + authUser,
                e);
    } finally {
        DbUtil.closeAllConnections(pst, con, null);
    }
}

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

/**
 * Deletes references from the specified table when the object is being deleted
 *
 * @param db/*from w w  w .  jav  a2  s .  co  m*/
 * @param objectId
 * @param table
 * @param uniqueField
 * @throws SQLException
 */
public static void delete(Connection db, int objectId, String table, String uniqueField) throws SQLException {
    PreparedStatement pst = db
            .prepareStatement("DELETE FROM " + table + "_rating " + "WHERE " + uniqueField + " = ? ");
    pst.setInt(1, objectId);
    pst.execute();
    pst.close();
}

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

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