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:net.dv8tion.discord.commands.TodoCommand.java

private void handleCreate(MessageReceivedEvent e, String[] args) throws SQLException {
    checkArgs(args, 2, "No ListName for the new todo list was provided. Usage: `" + getAliases().get(0)
            + " create [ListName]`");

    String label = args[2].toLowerCase();
    TodoList todoList = todoLists.get(label);

    if (todoList != null) {
        sendMessage(e, "A todo list already exists with the name `" + label + "`.");
        return;//from   ww  w . j a  v  a 2 s.  c om
    }

    PreparedStatement addTodoList = Database.getInstance().getStatement(ADD_TODO_LIST);
    addTodoList.setString(1, label); //Label
    addTodoList.setString(2, e.getAuthor().getId());//OwnerId
    addTodoList.setBoolean(3, false); //Locked
    if (addTodoList.executeUpdate() == 0)
        throw new SQLException(ADD_TODO_LIST + " reported no modified rows!");

    todoList = new TodoList(Database.getAutoIncrement(addTodoList, 1), label, e.getAuthor().getId(), false);
    todoLists.put(label, todoList);
    addTodoList.clearParameters();

    sendMessage(e, "Created `" + label + "` todo list. Use `" + getAliases().get(0) + " add " + label
            + " [content...]` " + "to add entries to this todo list.");
}

From source file:com.liferay.portal.upgrade.util.Table.java

public void setColumn(PreparedStatement ps, int index, Integer type, String value) throws Exception {

    int t = type.intValue();

    int paramIndex = index + 1;

    if (t == Types.BIGINT) {
        ps.setLong(paramIndex, GetterUtil.getLong(value));
    } else if (t == Types.BOOLEAN) {
        ps.setBoolean(paramIndex, GetterUtil.getBoolean(value));
    } else if ((t == Types.CLOB) || (t == Types.VARCHAR)) {
        value = StringUtil.replace(value, SAFE_CHARS[1], SAFE_CHARS[0]);

        ps.setString(paramIndex, value);
    } else if (t == Types.DOUBLE) {
        ps.setDouble(paramIndex, GetterUtil.getDouble(value));
    } else if (t == Types.FLOAT) {
        ps.setFloat(paramIndex, GetterUtil.getFloat(value));
    } else if (t == Types.INTEGER) {
        ps.setInt(paramIndex, GetterUtil.getInteger(value));
    } else if (t == Types.SMALLINT) {
        ps.setShort(paramIndex, GetterUtil.getShort(value));
    } else if (t == Types.TIMESTAMP) {
        if (StringPool.NULL.equals(value)) {
            ps.setTimestamp(paramIndex, null);
        } else {/*from  www .  j a  v a2 s. c  om*/
            DateFormat df = DateUtil.getISOFormat();

            ps.setTimestamp(paramIndex, new Timestamp(df.parse(value).getTime()));
        }
    } else {
        throw new UpgradeException("Upgrade code using unsupported class type " + type);
    }
}

From source file:com.alfaariss.oa.engine.user.provisioning.storage.internal.jdbc.JDBCInternalStorage.java

/**
 * Insert the supplied user in the account table.
 * @param oConnection the connection/*w  w w .ja v  a 2  s  .  c o m*/
 * @param user the user that must be inserted
 * @throws UserException if insertion fails
 */
private void insertAccount(Connection oConnection, ProvisioningUser user) throws UserException {
    PreparedStatement oPreparedStatement = null;
    try {
        oPreparedStatement = oConnection.prepareStatement(_sAccountInsert);
        oPreparedStatement.setString(1, user.getID());
        oPreparedStatement.setBoolean(2, user.isEnabled());

        if (oPreparedStatement.executeUpdate() != 1) {
            _logger.error("Could not insert account for user with id: " + user.getID());
            throw new UserException(SystemErrors.ERROR_RESOURCE_INSERT);
        }
    } catch (UserException e) {
        throw e;
    } catch (SQLException e) {
        _logger.error("Could not insert account for user with id: " + user.getID(), e);
        throw new UserException(SystemErrors.ERROR_RESOURCE_INSERT);
    } catch (Exception e) {
        _logger.fatal("Could not insert account", e);
        throw new UserException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (oPreparedStatement != null)
                oPreparedStatement.close();
        } catch (Exception e) {
            _logger.error("Could not close statement", e);
        }
    }
}

From source file:mysql5.MySQL5PlayerDAO.java

/**
 * {@inheritDoc} - Nemiroff//  ww  w  . ja  v  a 2 s .c o m
 */
@Override
public void setPlayersOffline(final boolean online) {
    DB.insertUpdate("UPDATE players SET online=?", new IUStH() {
        @Override
        public void handleInsertUpdate(PreparedStatement stmt) throws SQLException {
            stmt.setBoolean(1, online);
            stmt.execute();
        }
    });
}

From source file:org.cloudfoundry.identity.uaa.provider.saml.idp.JdbcSamlServiceProviderProvisioning.java

@Override
public SamlServiceProvider create(final SamlServiceProvider serviceProvider) {
    validate(serviceProvider);//from w  w w .jav a2 s.  com
    final String id = UUID.randomUUID().toString();
    try {
        jdbcTemplate.update(CREATE_SERVICE_PROVIDER_SQL, new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps) throws SQLException {
                int pos = 1;
                ps.setString(pos++, id);
                ps.setInt(pos++, serviceProvider.getVersion());
                ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis()));
                ps.setTimestamp(pos++, new Timestamp(System.currentTimeMillis()));
                ps.setString(pos++, serviceProvider.getName());
                ps.setString(pos++, serviceProvider.getEntityId());
                ps.setString(pos++, JsonUtils.writeValueAsString(serviceProvider.getConfig()));
                ps.setString(pos++, serviceProvider.getIdentityZoneId());
                ps.setBoolean(pos++, serviceProvider.isActive());
            }
        });
    } catch (DuplicateKeyException e) {
        throw new SamlSpAlreadyExistsException(e.getMostSpecificCause().getMessage());
    }
    return retrieve(id);
}

From source file:org.jobjects.dao.annotation.ManagerTools.java

protected final void setAll(PreparedStatement pstmt, int i, Object obj) throws SQLException {
    if (obj instanceof Boolean) {
        pstmt.setBoolean(i, ((Boolean) obj).booleanValue());
    }// www .  j a  va2  s  .c  o m
    if (obj instanceof Byte) {
        pstmt.setByte(i, ((Byte) obj).byteValue());
    }
    if (obj instanceof Short) {
        pstmt.setShort(i, ((Short) obj).shortValue());
    }
    if (obj instanceof Integer) {
        pstmt.setInt(i, ((Integer) obj).intValue());
    }
    if (obj instanceof Long) {
        pstmt.setLong(i, ((Long) obj).longValue());
    }
    if (obj instanceof Float) {
        pstmt.setFloat(i, ((Float) obj).floatValue());
    }
    if (obj instanceof Double) {
        pstmt.setDouble(i, ((Double) obj).doubleValue());
    }
    if (obj instanceof Timestamp) {
        pstmt.setTimestamp(i, ((Timestamp) obj));
    }
    if (obj instanceof Date) {
        pstmt.setDate(i, ((Date) obj));
    }
    if (obj instanceof BigDecimal) {
        pstmt.setBigDecimal(i, ((BigDecimal) obj));
    }
    if (obj instanceof String) {
        pstmt.setString(i, ((String) obj));
    }
}

From source file:org.atricore.idbus.idojos.dbsessionstore.DbSessionStore.java

/**
 * Loads all sessions whose valid property is equals to the received argument.
 *
 * @see #setLoadByValidQuery(String)/*w  w w .  j  a  v  a 2  s  .  c o m*/
 */
public BaseSession[] loadByValid(boolean valid) throws SSOSessionException {
    BaseSession[] retval = null;
    Connection conn = null;
    PreparedStatement stmt = null;

    try {
        conn = getConnection();
        stmt = conn.prepareStatement(_loadByValidQuery);
        stmt.setBoolean(1, valid);

        final ResultSet rs = stmt.executeQuery();
        retval = getSessions(rs);

        rs.close();
    } catch (Exception e) {
        if (__log.isDebugEnabled())
            __log.debug(e, e);
        throw new SSOSessionException(e);
    } finally {
        close(stmt);
        close(conn);
    }

    return retval;
}

From source file:org.rhq.enterprise.server.core.plugin.AgentPluginScanner.java

private void setEnabledFlag(Connection conn, PreparedStatement ps, int index, boolean enabled)
        throws Exception {
    if (null == this.dbType) {
        this.dbType = DatabaseTypeFactory.getDatabaseType(conn);
    }// ww  w .j  av  a  2  s  . c  o  m
    if (dbType instanceof PostgresqlDatabaseType || dbType instanceof H2DatabaseType) {
        ps.setBoolean(index, enabled);
    } else if (dbType instanceof OracleDatabaseType || dbType instanceof SQLServerDatabaseType) {
        ps.setInt(index, (enabled ? 1 : 0));
    } else {
        throw new RuntimeException("Unknown database type : " + dbType);
    }
}

From source file:org.sipfoundry.sipxconfig.firewall.FirewallManagerImpl.java

@Override
public void saveRules(List<EditableFirewallRule> rules) {
    m_jdbc.execute("delete from firewall_rule");
    String sql = "insert into firewall_rule (firewall_rule_id, firewall_server_group_id, "
            + "system_id, address_type, prioritize) values (nextval('firewall_rule_seq'),?,?,?,?)";
    final EditableFirewallRule[] changed = getChanged(rules);
    if (changed.length == 0) {
        return;//from w  w  w .java 2s  .c  o  m
    }
    BatchPreparedStatementSetter inserter = new BatchPreparedStatementSetter() {
        public int getBatchSize() {
            return changed.length;
        }

        public void setValues(PreparedStatement arg, int i) throws SQLException {
            EditableFirewallRule rule = changed[i];
            ServerGroup serverGroup = rule.getServerGroup();
            if (serverGroup == null) {
                arg.setNull(1, Types.INTEGER);
                arg.setString(2, rule.getSystemId().toString());
            } else {
                arg.setInt(1, serverGroup == null ? 0 : serverGroup.getId());
                arg.setNull(2, Types.VARCHAR);
            }
            arg.setString(3, rule.getAddressType().getId());
            arg.setBoolean(4, rule.isPriority());
        }
    };
    m_jdbc.batchUpdate(sql, inserter);
}