Example usage for java.sql PreparedStatement setLong

List of usage examples for java.sql PreparedStatement setLong

Introduction

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

Prototype

void setLong(int parameterIndex, long x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java long value.

Usage

From source file:com.mobilewallet.users.dao.UserQuestionsDAO.java

public List<UserQuestionsDTO> userQuestions(long userId, int begin, int end) {
    Connection connection = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;/*from  ww  w  . j  a v a2 s .  c  o  m*/
    List<UserQuestionsDTO> userQuestionsList = new ArrayList<UserQuestionsDTO>();
    UserQuestionsDTO userQuestions = null;
    try {
        connection = dataSource.getConnection();
        pstmt = connection.prepareStatement(getUserQuestiosQuery);
        pstmt.setLong(1, userId);
        pstmt.setInt(2, begin);
        pstmt.setInt(3, end);
        rs = pstmt.executeQuery();

        if (rs.next()) {
            userQuestions = new UserQuestionsDTO();
            userQuestions.setQuestion(rs.getString("uq_question"));
            userQuestions.setAnswerA(rs.getString("uq_answerA"));
            userQuestions.setAnswerB(rs.getString("uq_answerB"));
            userQuestions.setAnswerC(rs.getString("uq_answerC"));
            userQuestions.setAnswerD(rs.getString("uq_answerD"));
            userQuestions.setAnswer(rs.getString("uq_answer"));
            userQuestions.setAnswer(rs.getString("status"));
            userQuestionsList.add(userQuestions);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception ex) {

        }
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (Exception ex) {

        }
    }
    return userQuestionsList;
}

From source file:com.fluidops.iwb.wiki.WikiSQLStorageBase.java

@Override
protected boolean deleteRevisionFromStorage(URI resource, WikiRevision rev) {
    PreparedStatement prep = null;
    try {// w ww.ja v a 2  s .c  o m
        Connection conn = getConnection();
        prep = conn.prepareStatement("delete from revisions where name=? and date=?;");
        prep.setString(1, resource.stringValue());
        prep.setLong(2, rev.date.getTime());

        boolean res = prep.execute();
        SQL.monitorWrite();
        return res;
    } catch (SQLException e) {
        SQL.monitorWriteFailure();
        throw new RuntimeException("Delete revision failed.", e);
    } finally {
        SQL.closeQuietly(prep);
    }
}

From source file:com.fluidops.iwb.wiki.WikiSQLStorageBase.java

@Override
public boolean deleteAllOlder(URI resource, Date date) {
    PreparedStatement prep = null;
    try {/*  w  w w .  j  ava  2 s.co  m*/
        Connection conn = getConnection();
        prep = conn.prepareStatement("delete from revisions where name=? and date>?;");
        prep.setString(1, resource.stringValue());
        prep.setLong(2, date.getTime());

        boolean res = prep.execute();
        SQL.monitorWrite();
        return res;
    } catch (SQLException e) {
        SQL.monitorWriteFailure();
        throw new RuntimeException("Delete revisions failed", e);
    } finally {
        SQL.closeQuietly(prep);
    }
}

From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java

@Override
public void insertExecutionStates(final List<ExecutionMessage> stateMessages) {
    String insertExecStateSQL = INSERT_EXEC_STATE;
    insertExecutionJDBCTemplate.batchUpdate(insertExecStateSQL, new BatchPreparedStatementSetter() {

        @Override//from   w w  w  . jav  a2s .  c o m
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ExecutionMessage msg = stateMessages.get(i);
            ps.setLong(1, msg.getExecStateId());
            ps.setString(2, msg.getMsgId());
            ps.setBytes(3, msg.getPayload().getData());
        }

        @Override
        public int getBatchSize() {
            return stateMessages.size();
        }
    });
}

From source file:com.amazonbird.announce.ProductMgrImpl.java

public void removeProduct(long id) {

    Connection connection = null;
    PreparedStatement ps = null;
    try {/* w w w  .  j a v a 2s. co  m*/
        connection = dbMgr.getConnection();
        ps = connection.prepareStatement(DELETE_PRODUCT);
        ps.setLong(1, id);

        ps.executeUpdate();

        logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString());
    } catch (SQLException ex) {
        logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex);
    } finally {
        dbMgr.closeResources(connection, ps, null);
    }

}

From source file:io.cloudslang.engine.queue.repositories.ExecutionQueueRepositoryImpl.java

@Override
public void insertExecutionQueue(final List<ExecutionMessage> messages, final long version) {
    // insert execution queue table
    // id, exec_state_id, assigned_worker, status, create_time
    String insertQueueSQL = INSERT_QUEUE;

    long t = System.currentTimeMillis();
    insertExecutionJDBCTemplate.batchUpdate(insertQueueSQL, new BatchPreparedStatementSetter() {
        @Override/*from  www  .j a v  a2 s  .  c  om*/
        public void setValues(PreparedStatement ps, int i) throws SQLException {
            ExecutionMessage msg = messages.get(i);
            ps.setLong(1, idGen.next());
            ps.setLong(2, msg.getExecStateId());
            ps.setString(3, msg.getWorkerId());
            ps.setString(4, msg.getWorkerGroup());
            ps.setInt(5, msg.getStatus().getNumber());
            ps.setInt(6, msg.getMsgSeqId());
            ps.setLong(7, Calendar.getInstance().getTimeInMillis());
            ps.setLong(8, version);
        }

        @Override
        public int getBatchSize() {
            return messages.size();
        }
    });
    t = System.currentTimeMillis() - t;
    if (logger.isDebugEnabled())
        logger.debug("Insert to queue: " + messages.size() + "/" + t + " messages/ms");
}

From source file:com.l2jfree.gameserver.instancemanager.RecommendationManager.java

private void update(L2Player player, int recomLeft, int evalPoints) {
    Connection con = null;/*from   w ww.  j  ava 2s .c  o m*/
    PreparedStatement ps = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        ps = con.prepareStatement(UPDATE_RECOMMENDATION_INFO);
        ps.setInt(1, recomLeft);
        ps.setInt(2, evalPoints);
        ps.setLong(3, nextUpdate - DAY);
        ps.setInt(4, player.getObjectId());
        ps.executeUpdate();
        ps.close();
        player.setEvaluationCount(recomLeft);
        player.setEvalPoints(evalPoints);
    } catch (SQLException e) {
        _log.error("Failed updating player's (" + player.getName() + ") recommendations!", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.fluidops.iwb.wiki.WikiSQLStorageBase.java

@Override
protected void storeWikiContent(URI resource, String content, WikiRevision revision) throws IOException {
    PreparedStatement prep = null;
    try {/*ww  w  .  j a v a 2s.c  o m*/
        Connection conn = getConnection();
        prep = conn.prepareStatement("insert into revisions values (?, ?, ?, ?, ?, ?, ?);");

        prep.setString(1, resource.stringValue());
        prep.setLong(2, revision.date.getTime());
        prep.setLong(3, revision.size);
        prep.setString(4, revision.comment);
        prep.setString(5, revision.user);
        prep.setString(6, revision.security);
        if (com.fluidops.iwb.util.Config.getConfig().getCompressWikiInDatabase())
            prep.setBytes(7, gzip(content));
        else
            prep.setString(7, content);

        prep.execute();
        SQL.monitorWrite();
    } catch (SQLException e) {
        SQL.monitorWriteFailure();
        throw new IOException("Storing wiki content failed.", e);
    } finally {
        SQL.closeQuietly(prep);
    }
}

From source file:com.flexive.ejb.beans.HistoryTrackerEngineBean.java

/**
 * {@inheritDoc}//from  w  w  w  .ja  v a2 s.  co m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public void track(FxType type, FxPK pk, String data, String key, Object... args) {
    Connection con = null;
    PreparedStatement ps = null;
    try {
        final UserTicket ticket = FxContext.getUserTicket();
        con = Database.getDbConnection();
        ps = con.prepareStatement(StorageManager.escapeReservedWords(HISTORY_INSERT));
        ps.setLong(1, ticket.getUserId());
        ps.setString(2, ticket.getLoginName());

        ps.setLong(3, System.currentTimeMillis());
        ps.setString(4, key);
        StorageManager.setBigString(ps, 5, StringUtils.join(args, '|'));
        try {
            ps.setString(6, FxSharedUtils.getLocalizedMessage("History", FxLanguage.ENGLISH, "en", key, args));
        } catch (Exception e) {
            ps.setString(6, key);
        }
        FxContext si = FxContext.get();
        ps.setString(7, (si.getSessionId() == null ? "<unknown>" : si.getSessionId()));
        ps.setString(8, (si.getApplicationId() == null ? "<unknown>" : si.getApplicationId()));
        ps.setString(9, (si.getRemoteHost() == null ? "<unknown>" : si.getRemoteHost()));
        if (type != null) {
            ps.setLong(10, type.getId());
            ps.setString(11, type.getName());
        } else {
            ps.setNull(10, java.sql.Types.NUMERIC);
            ps.setNull(11, java.sql.Types.VARCHAR);
        }
        if (pk != null) {
            ps.setLong(12, pk.getId());
            ps.setInt(13, pk.getVersion());
        } else {
            ps.setNull(12, java.sql.Types.NUMERIC);
            ps.setNull(13, java.sql.Types.NUMERIC);
        }
        if (data != null)
            StorageManager.setBigString(ps, 14, data);
        else
            ps.setNull(14, java.sql.Types.VARCHAR);
        ps.executeUpdate();
    } catch (Exception ex) {
        LOG.error(ex.getMessage());
    } finally {
        Database.closeObjects(HistoryTrackerEngineBean.class, con, ps);
    }
}

From source file:net.mindengine.oculus.frontend.service.issue.JdbcIssueDAO.java

@Override
public void linkTestsToIssue(IssueCollation issueCollation) throws Exception {
    /*/*from  w  w w  .jav  a2s  .c om*/
     * Inserting into issue_collations table first because then we will use
     * its generated index
     */
    PreparedStatement ps = getConnection()
            .prepareStatement("insert into issue_collations (issue_id, reason_pattern) values (?,?)");
    ps.setLong(1, issueCollation.getIssueId());
    ps.setString(2, issueCollation.getReasonPattern());

    logger.info(ps);

    ps.execute();
    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        issueCollation.setId(rs.getLong(1));
    } else
        throw new Exception("An error appeared while linking tests to issue");

    /*
     * Inserting all tests into issue_collation_tests table
     */
    for (IssueCollationTest test : issueCollation.getTests()) {
        update("insert into issue_collation_tests (issue_collation_id, test_id, test_name) values ("
                + issueCollation.getId() + "," + test.getTestId() + ", :testName)", "testName",
                test.getTestName());
    }

    update("update issues set dependent_tests = dependent_tests + :size where id = :id", "size",
            issueCollation.getTests().size(), "id", issueCollation.getIssueId());

    /*
     * Inserting all conditions into issue_collation_conditions table
     */
    for (IssueCollationCondition condition : issueCollation.getConditions()) {
        update("insert into issue_collation_conditions (issue_collation_id, trm_property_id, value) values (:issueCollationId, :trmPropertyId, :value)",
                "issueCollationId", issueCollation.getId(), "trmPropertyId", condition.getTrmPropertyId(),
                "value", condition.getValue());

    }
}