Example usage for java.sql PreparedStatement setBoolean

List of usage examples for java.sql PreparedStatement setBoolean

Introduction

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

Prototype

void setBoolean(int parameterIndex, boolean x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java boolean value.

Usage

From source file:iddb.runtime.db.model.dao.impl.mysql.PenaltyDAOImpl.java

@Override
public Penalty findLastActivePenalty(Long player, Integer type) {
    String sql = "select * from penalty where playerid = ? and type = ? and active = ? order by updated desc limit 1";
    Connection conn = null;/* ww w  .j  ava 2  s  . c  om*/
    Penalty penalty = null;
    try {
        conn = ConnectionFactory.getSecondaryConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setLong(1, player);
        st.setInt(2, type.intValue());
        st.setBoolean(3, true);
        ResultSet rs = st.executeQuery();
        if (rs.next()) {
            penalty = new Penalty();
            loadPenalty(penalty, rs);
        }
    } catch (SQLException e) {
        logger.error("findByPlayerAndTypeAndActive: {}", e);
    } catch (IOException e) {
        logger.error("findByPlayerAndTypeAndActive: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
    return penalty;
}

From source file:iddb.runtime.db.model.dao.impl.mysql.PenaltyDAOImpl.java

@Override
public List<Penalty> findByPlayerAndTypeAndActive(Long player, Integer type) {
    String sql = "select * from penalty where playerid = ? and type = ? and active = ? order by created desc";
    Connection conn = null;//from   w ww .  j av  a 2 s .  c  o  m
    List<Penalty> list = new ArrayList<Penalty>();
    try {
        conn = ConnectionFactory.getSecondaryConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setLong(1, player);
        st.setInt(2, type.intValue());
        st.setBoolean(3, true);
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            Penalty penalty = new Penalty();
            loadPenalty(penalty, rs);
            list.add(penalty);
        }
    } catch (SQLException e) {
        logger.error("findByPlayerAndTypeAndActive: {}", e);
    } catch (IOException e) {
        logger.error("findByPlayerAndTypeAndActive: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
    return list;
}

From source file:edu.jhu.pha.vospace.meta.MySQLMetaStore2.java

@Override
public String createShare(final VospaceId identifier, final String groupId, final boolean write_perm) {
    final String shareKey = RandomStringUtils.randomAlphanumeric(15);

    if (groupId != null && !groupId.isEmpty()) {
        DbPoolServlet.goSql("Adding new share for container",
                "insert into container_shares (share_id, container_id, group_id, share_write_permission) select ?, container_id, group_id, ? from containers JOIN user_identities ON containers.user_id = user_identities.user_id JOIN groups WHERE identity = ? AND container_name = ? and group_id = ?",
                new SqlWorker<Integer>() {
                    @Override/*w  w w.  j  a  v a  2s.  c  o m*/
                    public Integer go(Connection conn, PreparedStatement stmt) throws SQLException {
                        stmt.setString(1, shareKey);
                        stmt.setBoolean(2, write_perm);
                        stmt.setString(3, owner);
                        stmt.setString(4, identifier.getNodePath().getContainerName());
                        stmt.setString(5, groupId);
                        return stmt.executeUpdate();
                    }
                });
    } else {
        DbPoolServlet.goSql("Adding new share for container",
                "insert into container_shares (share_id, container_id, share_write_permission) select ?, container_id, ? from containers JOIN user_identities ON containers.user_id = user_identities.user_id WHERE identity = ? AND container_name = ?",
                new SqlWorker<Integer>() {
                    @Override
                    public Integer go(Connection conn, PreparedStatement stmt) throws SQLException {
                        stmt.setString(1, shareKey);
                        stmt.setBoolean(2, write_perm);
                        stmt.setString(3, owner);
                        stmt.setString(4, identifier.getNodePath().getContainerName());
                        return stmt.executeUpdate();
                    }
                });
    }
    return shareKey;
}

From source file:com.concursive.connect.web.modules.register.beans.RegisterBean.java

/**
 * Gets the alreadyRegistered attribute of the RegisterBean object
 *
 * @param db Description of the Parameter
 * @return The alreadyRegistered value/* w w w  . j a v  a 2 s  . c  o m*/
 * @throws SQLException Description of the Exception
 */
public boolean isAlreadyRegistered(Connection db) throws SQLException {
    PreparedStatement pst = db.prepareStatement(
            "SELECT count(*) AS records " + "FROM users " + "WHERE lower(email) = ? " + "AND registered = ?");
    pst.setString(1, email.toLowerCase());
    pst.setBoolean(2, true);
    ResultSet rs = pst.executeQuery();
    rs.next();
    int count = rs.getInt("records");
    rs.close();
    pst.close();
    return count >= 1;
}

From source file:org.schedoscope.metascope.tasks.repository.mysql.impl.ViewEntityMySQLRepository.java

@Override
public void insertOrUpdate(Connection connection, ViewEntity viewEntity) {
    String insertViewSql = "insert into view_entity (" + JDBCUtil.getDatabaseColumnsForClass(ViewEntity.class)
            + ") values (" + JDBCUtil.getValuesCountForClass(ViewEntity.class) + ") "
            + "on duplicate key update " + MySQLUtil.getOnDuplicateKeyString(ViewEntity.class);
    PreparedStatement stmt = null;
    try {/*from  w w w  .j  a v  a2 s . co m*/
        stmt = connection.prepareStatement(insertViewSql);
        stmt.setString(1, viewEntity.getUrlPath());
        stmt.setString(2, viewEntity.getFqdn());
        stmt.setString(3, viewEntity.getStatus());
        stmt.setString(4, viewEntity.getParameterString());
        stmt.setString(5, viewEntity.getInternalViewId());
        stmt.setLong(6, viewEntity.getTransformationStart());
        stmt.setLong(7, viewEntity.getTransformationEnd());
        stmt.setLong(8, viewEntity.getCreatedAt());
        stmt.setBoolean(9, viewEntity.isRowJobFinished());
        stmt.setLong(10, viewEntity.getRows());
        stmt.setString(11, viewEntity.getFqdn());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not save view", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:net.dv8tion.discord.commands.TodoCommand.java

private void handleCheck(MessageReceivedEvent e, String[] args, boolean completed) throws SQLException {
    checkArgs(args, 2, "No todo ListName was specified. Usage: `" + getAliases().get(0)
            + " mark/unmark [ListName] [EntryIndex]`");
    checkArgs(args, 3, "No todo EntryIndex was specified. Usage: `" + getAliases().get(0)
            + " mark/unmark [ListName] [EntryIndex]`");

    String label = args[2].toLowerCase();
    TodoList todoList = todoLists.get(label);
    if (todoList == null) {
        sendMessage(e, "Sorry, `" + label + "` isn't a known todo list.");
        return;/*from  www.  ja v  a 2 s.  com*/
    }

    String todoEntryString = args[3];

    if (todoEntryString.equals("*")) {
        PreparedStatement setTodoEntryChecked = Database.getInstance().getStatement(SET_TODO_ENTRIES_CHECKED);
        setTodoEntryChecked.setBoolean(1, completed);
        setTodoEntryChecked.setInt(2, todoList.id);
        if (setTodoEntryChecked.executeUpdate() == 0)
            throw new SQLException(SET_TODO_ENTRIES_CHECKED + " reported no updated rows!");

        todoList.entries.forEach(todoEntry -> todoEntry.checked = completed);

        sendMessage(e, "Set all entries in the `" + label + "` todo list to **"
                + (completed ? "complete**" : "incomplete**"));
    } else {
        int todoEntryIndex;
        try {
            //We subtract 1 from the provided value because entries are listed from 1 and higher.
            // People don't start counting from 0, so when we display the list of entries, we start from.
            // This means that the entry index they enter will actually be 1 greater than the actual entry.
            todoEntryIndex = Integer.parseInt(todoEntryString) - 1;
        } catch (NumberFormatException ex) {
            sendMessage(e, "The provided value as an index to mark was not a number. Value provided: `"
                    + todoEntryString + "`");
            return;
        }

        if (todoEntryIndex < 0 || todoEntryIndex + 1 > todoList.entries.size()) {
            //We add 1 back to the todoEntry because we subtracted 1 from it above. (Basically, we make it human readable again)
            sendMessage(e, "The provided index to mark does not exist in this Todo list. Value provided: `"
                    + (todoEntryIndex + 1) + "`");
            return;
        }

        TodoEntry todoEntry = todoList.entries.get(todoEntryIndex);
        if (todoEntry.checked != completed) {
            PreparedStatement setTodoEntryChecked = Database.getInstance().getStatement(SET_TODO_ENTRY_CHECKED);
            setTodoEntryChecked.setBoolean(1, completed);
            setTodoEntryChecked.setInt(2, todoEntry.id);
            if (setTodoEntryChecked.executeUpdate() == 0)
                throw new SQLException(SET_TODO_ENTRY_CHECKED + " reported no updated rows!");

            todoEntry.checked = completed;
        }

        sendMessage(e, "Item `" + (todoEntryIndex + 1) + "` in `" + label + "` was marked as **"
                + (completed ? "completed**" : "incomplete**"));
    }
}

From source file:com.concursive.connect.web.modules.communications.utils.EmailUpdatesUtils.java

public static void manageQueue(Connection db, TeamMember teamMember) throws SQLException {
    //Determine if the member is part of any other projects and has a matching email updates preference
    PreparedStatement pst = db.prepareStatement("SELECT count(*) AS record_count " + "FROM project_team pt "
            + "WHERE pt.user_id = ? " + "AND pt.email_updates_schedule = ? ");
    int i = 0;//  w ww.  jav a  2  s  .  c  o  m
    pst.setInt(++i, teamMember.getUserId());
    pst.setInt(++i, teamMember.getEmailUpdatesSchedule());
    ResultSet rs = pst.executeQuery();
    int records = 0;
    if (rs.next()) {
        records = rs.getInt("record_count");
    }
    rs.close();
    pst.close();

    if (records == 0) {
        //Delete the queue since it is no longer needed.
        String field = "";
        int emailUpdatesSchedule = teamMember.getEmailUpdatesSchedule();
        if (emailUpdatesSchedule > 0) {
            if (emailUpdatesSchedule == TeamMember.EMAIL_OFTEN) {
                field = "schedule_often";
            } else if (emailUpdatesSchedule == TeamMember.EMAIL_DAILY) {
                field = "schedule_daily";
            } else if (emailUpdatesSchedule == TeamMember.EMAIL_WEEKLY) {
                field = "schedule_weekly";
            } else if (emailUpdatesSchedule == TeamMember.EMAIL_MONTHLY) {
                field = "schedule_monthly";
            }
            i = 0;
            pst = db.prepareStatement(
                    "DELETE FROM email_updates_queue " + "WHERE enteredby = ? AND " + field + " = ? ");
            pst.setInt(++i, teamMember.getUserId());
            pst.setBoolean(++i, true);
            pst.executeUpdate();
            pst.close();
        }
    }
}

From source file:org.apache.ode.scheduler.simple.jdbc.SchedulerDAOConnectionImpl.java

public boolean insertJob(JobDAO job, String nodeId, boolean loaded) throws DatabaseException {
    if (__log.isDebugEnabled())
        __log.debug("insertJob " + job.getJobId() + " on node " + nodeId + " loaded=" + loaded);

    Connection con = null;/*from ww w.  j  a  v a  2 s.  com*/
    PreparedStatement ps = null;
    try {
        int i = 1;
        con = getConnection();
        ps = con.prepareStatement(SAVE_JOB);
        ps.setString(i++, job.getJobId());
        ps.setString(i++, nodeId);
        ps.setLong(i++, job.getScheduledDate());
        ps.setBoolean(i++, loaded);
        ps.setBoolean(i++, job.isTransacted());

        JobDetails details = job.getDetails();

        ps.setObject(i++, details.instanceId, Types.BIGINT);
        ps.setObject(i++, details.mexId, Types.VARCHAR);
        ps.setObject(i++, details.processId, Types.VARCHAR);
        ps.setObject(i++, details.type, Types.VARCHAR);
        ps.setObject(i++, details.channel, Types.VARCHAR);
        ps.setObject(i++, details.correlatorId, Types.VARCHAR);
        ps.setObject(i++, details.correlationKeySet, Types.VARCHAR);
        ps.setObject(i++, details.retryCount, Types.INTEGER);
        ps.setObject(i++, details.inMem, Types.BOOLEAN);

        if (details.detailsExt == null || details.detailsExt.size() == 0) {
            ps.setObject(i++, null, Types.BLOB);
        } else {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try {
                StreamUtils.write(bos, (Serializable) details.detailsExt);
            } catch (Exception ex) {
                __log.error("Error serializing job detail: " + job.getDetails());
                throw new DatabaseException(ex);
            }
            ps.setObject(i++, bos.toByteArray(), Types.BLOB);
        }

        return ps.executeUpdate() == 1;
    } catch (SQLException se) {
        throw new DatabaseException(se);
    } finally {
        close(ps);
        close(con);
    }
}

From source file:org.schedoscope.metascope.tasks.repository.jdbc.impl.ViewEntityJdbcRepository.java

@Override
public void save(Connection connection, ViewEntity viewEntity) {
    String insertViewSql = "insert into view_entity (" + JDBCUtil.getDatabaseColumnsForClass(ViewEntity.class)
            + ") values (" + JDBCUtil.getValuesCountForClass(ViewEntity.class) + ")";
    PreparedStatement stmt = null;
    try {//from   www  .j  a  v a2 s . c  o  m
        stmt = connection.prepareStatement(insertViewSql);
        stmt.setString(1, viewEntity.getUrlPath());
        stmt.setString(2, viewEntity.getFqdn());
        stmt.setString(3, viewEntity.getStatus());
        stmt.setString(4, viewEntity.getParameterString());
        stmt.setString(5, viewEntity.getInternalViewId());
        stmt.setLong(6, viewEntity.getTransformationStart());
        stmt.setLong(7, viewEntity.getTransformationEnd());
        stmt.setLong(8, viewEntity.getCreatedAt());
        stmt.setBoolean(9, viewEntity.isRowJobFinished());
        stmt.setLong(10, viewEntity.getRows());
        stmt.setString(11, viewEntity.getFqdn());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not save view", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:org.schedoscope.metascope.tasks.repository.jdbc.impl.ViewEntityJdbcRepository.java

@Override
public void update(Connection connection, ViewEntity viewEntity) {
    String updateViewSql = "update view_entity set " + JDBCUtil.getSetExpressionForClass(ViewEntity.class)
            + " where " + ViewEntity.URL_PATH + " = ?";
    PreparedStatement stmt = null;
    try {/* ww w. ja va2 s  .  c o  m*/
        stmt = connection.prepareStatement(updateViewSql);
        stmt.setString(1, viewEntity.getUrlPath());
        stmt.setString(2, viewEntity.getFqdn());
        stmt.setString(3, viewEntity.getStatus());
        stmt.setString(4, viewEntity.getParameterString());
        stmt.setString(5, viewEntity.getInternalViewId());
        stmt.setLong(6, viewEntity.getTransformationStart());
        stmt.setLong(7, viewEntity.getTransformationEnd());
        stmt.setLong(8, viewEntity.getCreatedAt());
        stmt.setBoolean(9, viewEntity.isRowJobFinished());
        stmt.setLong(10, viewEntity.getRows());
        stmt.setString(11, viewEntity.getFqdn());
        stmt.setString(12, viewEntity.getUrlPath());
        stmt.execute();
    } catch (SQLException e) {
        LOG.error("Could not update view", e);
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}