Example usage for java.sql ResultSet getBoolean

List of usage examples for java.sql ResultSet getBoolean

Introduction

In this page you can find the example usage for java.sql ResultSet getBoolean.

Prototype

boolean getBoolean(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a boolean in the Java programming language.

Usage

From source file:net.duckling.falcon.api.orm.DAOUtils.java

private void setValueToObj(Field field, Object obj, ResultSet rs) {
    String setName = getSetMethodName(field.getName());
    String exceptionMsg = "???";
    try {/* w ww. ja  v a  2  s  .  c  o  m*/
        Method method = objClass.getMethod(setName, field.getType());
        if (isString(field)) {
            method.invoke(obj, new Object[] { rs.getString(getDBField(field.getName())) });
        } else if (isInt(field)) {
            method.invoke(obj, new Object[] { rs.getInt(getDBField(field.getName())) });
        } else if (isDate(field)) {
            method.invoke(obj, new Object[] { rs.getTimestamp(getDBField(field.getName())) });
        } else if (isBoolean(field)) {
            method.invoke(obj, new Object[] { rs.getBoolean(getDBField(field.getName())) });
        } else {
            LOG.debug("Unsupported type");
        }
    } catch (ReflectiveOperationException e) {
        LOG.debug(exceptionMsg + obj.getClass() + "@" + field, e);
    } catch (SQLException e) {
        LOG.debug(exceptionMsg + obj.getClass() + "@" + field, e);
    }
}

From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java

/**
 * @see eionet.meta.dao.ISchemaSetDAO#searchSchemaSets(eionet.meta.service.data.SchemaSetFilter)
 *///w  ww. j  av  a2  s .com
@Override
public SchemaSetsResult searchSchemaSets(SchemaSetFilter searchFilter) {

    int nameAttrId = getNameAttributeId();

    Map<String, Object> parameters = new HashMap<String, Object>();
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT SQL_CALC_FOUND_ROWS ss.*, ATTRIBUTE.VALUE as NAME_ATTR ");

    sql.append("FROM T_SCHEMA_SET ss ");
    sql.append("left outer join ATTRIBUTE on ");
    sql.append("(ss.SCHEMA_SET_ID=ATTRIBUTE.DATAELEM_ID and ATTRIBUTE.PARENT_TYPE=:attrParentType ");
    sql.append("and ATTRIBUTE.M_ATTRIBUTE_ID=:nameAttrId) ");

    parameters.put("attrParentType", DElemAttribute.ParentType.SCHEMA_SET.toString());
    parameters.put("nameAttrId", nameAttrId);

    sql.append("where ");
    String searchingUser = searchFilter.getSearchingUser();
    if (StringUtils.isBlank(searchingUser)) {
        sql.append("(ss.WORKING_COPY=false ");
        if (StringUtils.isEmpty(searchFilter.getRegStatus())
                && CollectionUtils.isEmpty(searchFilter.getRegStatuses())) {
            sql.append("AND ss.REG_STATUS IN ( :regStatusPublic ) ");
            parameters.put("regStatusPublic", RegStatus.getPublicStatuses());
        }
        sql.append(") ");
    } else {
        sql.append("(ss.WORKING_COPY=false or ss.WORKING_USER=:workingUser) ");
        parameters.put("workingUser", searchingUser);
    }

    // Where clause
    if (searchFilter.isValued()) {
        parameters.put("parentType", DElemAttribute.ParentType.SCHEMA_SET.toString());

        if (StringUtils.isNotEmpty(searchFilter.getIdentifier())) {
            sql.append("AND ");
            sql.append("ss.IDENTIFIER like :identifier ");
            String identifier = "%" + searchFilter.getIdentifier() + "%";
            parameters.put("identifier", identifier);
        }
        if (StringUtils.isNotEmpty(searchFilter.getRegStatus())) {
            sql.append("AND ");
            sql.append("ss.REG_STATUS = :regStatus ");
            parameters.put("regStatus", searchFilter.getRegStatus());
        } else if (searchFilter.getRegStatuses() != null && searchFilter.getRegStatuses().size() > 0) {
            sql.append(" AND ss.REG_STATUS IN ( :regStatuses ) ");
            parameters.put("regStatuses", searchFilter.getRegStatuses());
        }
        /*
         * if (searchFilter.isAttributesValued()) { for (int i = 0; i < searchFilter.getAttributes().size(); i++) { Attribute a
         * = searchFilter.getAttributes().get(i); String idKey = "attrId" + i; String valueKey = "attrValue" + i; if
         * (StringUtils.isNotEmpty(a.getValue())) { sql.append("AND "); sql.append("ss.SCHEMA_SET_ID IN ( ");
         * sql.append("SELECT a.DATAELEM_ID FROM ATTRIBUTE a WHERE "); sql.append("a.M_ATTRIBUTE_ID = :" + idKey +
         * " AND a.VALUE like :" + valueKey + " AND a.PARENT_TYPE = :parentType "); sql.append(") "); } parameters.put(idKey,
         * a.getId()); String value = "%" + a.getValue() + "%"; parameters.put(valueKey, value); } }
         */
        sql.append(getAttributesSqlConstraintAndAppendParams(searchFilter, parameters, "ss.SCHEMA_SET_ID"));
        sql.append(getComplexAttrsSqlConstraintAndAppendParams(searchFilter, parameters, "ss.SCHEMA_SET_ID"));
    }

    // Sorting
    if (StringUtils.isNotEmpty(searchFilter.getSortProperty())) {
        sql.append("ORDER BY ").append(searchFilter.getSortProperty());
        if (SortOrderEnum.ASCENDING.equals(searchFilter.getSortOrder())) {
            sql.append(" ASC ");
        } else {
            sql.append(" DESC ");
        }
    }
    if (searchFilter.isUsePaging()) {
        sql.append("LIMIT ").append(searchFilter.getOffset()).append(",").append(searchFilter.getPageSize());
    }

    // LOGGER.debug("SQL: " + sql.toString());

    List<SchemaSet> items = getNamedParameterJdbcTemplate().query(sql.toString(), parameters,
            new RowMapper<SchemaSet>() {
                @Override
                public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    SchemaSet ss = new SchemaSet();
                    ss.setId(rs.getInt("SCHEMA_SET_ID"));
                    ss.setIdentifier(rs.getString("IDENTIFIER"));
                    ss.setContinuityId(rs.getString("CONTINUITY_ID"));
                    ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS")));
                    ss.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
                    ss.setWorkingUser(rs.getString("WORKING_USER"));
                    ss.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
                    ss.setUserModified(rs.getString("USER_MODIFIED"));
                    ss.setComment(rs.getString("COMMENT"));
                    ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
                    ss.setNameAttribute(rs.getString("NAME_ATTR"));
                    ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED"));
                    return ss;
                }
            });

    String totalSql = "SELECT FOUND_ROWS()";
    int totalItems = getJdbcTemplate().queryForInt(totalSql);

    SchemaSetsResult result = new SchemaSetsResult(items, totalItems, searchFilter);
    return result;
}

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

/**
 * Retrieve the registered fields for all methods in the user profile.
 * @param sUserId the user id//from   www . j av a2s . com
 * @return a <code>Hashtable</code> with method id (key) and registered 
 * <code>Boolean</code> (value)
 * @throws UserException if selection fails
 */
private Hashtable<String, Boolean> getRegistered(String sUserId) throws UserException {
    Hashtable<String, Boolean> htRegistered = new Hashtable<String, Boolean>();
    PreparedStatement oPreparedStatement = null;
    ResultSet oResultSet = null;
    Connection oConnection = null;
    try {
        oConnection = _oDataSource.getConnection();
        oPreparedStatement = oConnection.prepareStatement(_sProfileRegisteredSelect);
        oPreparedStatement.setString(1, sUserId);
        oResultSet = oPreparedStatement.executeQuery();
        while (oResultSet.next()) {
            String sID = oResultSet.getString(COLUMN_PROFILE_AUTHSPID);
            boolean bRegistered = oResultSet.getBoolean(COLUMN_PROFILE_REGISTERED);

            htRegistered.put(sID, bRegistered);
        }
    } catch (SQLException e) {
        _logger.error("Could not retrieve profile registered for user with id: " + sUserId, e);
        throw new UserException(SystemErrors.ERROR_RESOURCE_RETRIEVE);
    } catch (Exception e) {
        _logger.error("Could not retrieve profile for user with id: " + sUserId, e);
        throw new UserException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (oResultSet != null)
                oResultSet.close();
        } catch (Exception e) {
            _logger.error("Could not close resultset", e);
        }

        try {
            if (oPreparedStatement != null)
                oPreparedStatement.close();
        } catch (Exception e) {
            _logger.error("Could not close statement", e);
        }

        try {
            if (oConnection != null)
                oConnection.close();
        } catch (Exception e) {
            _logger.error("Could not close connection", e);
        }
    }

    return htRegistered;
}

From source file:uk.org.rbc1b.roms.controller.report.ReportsController.java

private ReportResults extractResults(String sql) throws SQLException {
    Connection con = DataSourceUtils.getConnection(dataSource);
    Statement s = con.createStatement();

    ResultSet rs = s.executeQuery(sql);

    ReportResults reportResults = new ReportResults();

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    List<Integer> columnTypeIds = new ArrayList<Integer>();
    for (int i = 0; i < columnCount; i++) {
        columnTypeIds.add(rsmd.getColumnType(i + 1));
    }//from   www  .j  ava  2s  .co m

    reportResults.columnNames = new ArrayList<String>();
    for (int i = 0; i < columnCount; i++) {
        reportResults.columnNames.add(rsmd.getColumnLabel(i + 1));
    }

    reportResults.resultRows = new ArrayList<List<String>>();
    while (rs.next()) {
        List<String> resultRow = new ArrayList<String>();

        for (int i = 0; i < columnCount; i++) {
            Integer columnTypeId = columnTypeIds.get(i);
            if (columnTypeId.intValue() == Types.BOOLEAN || columnTypeId.intValue() == Types.BIT) {
                resultRow.add(Boolean.valueOf(rs.getBoolean(i + 1)).toString());
            } else {
                resultRow.add(rs.getString(i + 1));
            }
        }

        reportResults.resultRows.add(resultRow);
    }

    return reportResults;
}

From source file:com.mirth.connect.donkey.test.util.TestUtils.java

public static void assertMessageExists(Message message, boolean deepSearch) throws SQLException {
    long localChannelId = ChannelController.getInstance().getLocalChannelId(message.getChannelId());

    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet result = null;

    try {/*w  w  w  . j a va2 s.  c  om*/
        connection = getConnection();
        statement = connection.prepareStatement("SELECT * FROM d_m" + localChannelId + " WHERE id = ?");
        statement.setLong(1, message.getMessageId());
        result = statement.executeQuery();

        if (result.next()) {
            String serverId = result.getString("server_id");
            Boolean processed = result.getBoolean("processed");
            close(result);
            close(statement);

            assertTrue(testEquality(serverId, message.getServerId()));
            assertTrue(testEquality(processed, message.isProcessed()));

            if (deepSearch) {
                for (ConnectorMessage connectorMessage : message.getConnectorMessages().values()) {
                    assertConnectorMessageExists(connectorMessage, deepSearch, connection);
                }
            }
        } else {
            throw new AssertionError();
        }
    } finally {
        close(result);
        close(statement);
        close(connection);
    }
}

From source file:com.flexive.core.storage.genericSQL.GenericEnvironmentLoader.java

/**
 * {@inheritDoc}//from   w ww.  j a  va 2  s.  c  o  m
 */
@Override
public List<FxScriptInfo> loadScripts(Connection con)
        throws FxLoadException, FxNotFoundException, FxInvalidParameterException {
    PreparedStatement ps = null;
    String sql;
    List<FxScriptInfo> scripts = new ArrayList<FxScriptInfo>(10);
    try {
        //            1  2     3     4     5           6
        sql = "SELECT ID,SNAME,SDESC,STYPE,ACTIVE,IS_CACHED FROM " + TBL_SCRIPTS + " ORDER BY ID";
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs != null && rs.next())
            scripts.add(new FxScriptInfo(rs.getLong(1), FxScriptEvent.getById(rs.getLong(4)), rs.getString(2),
                    rs.getString(3), rs.getBoolean(5), rs.getBoolean(6)));
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.scripting.load.failed", -1, exc.getMessage());
    } finally {
        Database.closeObjects(GenericEnvironmentLoader.class, null, ps);
    }
    return scripts;
}

From source file:eionet.meta.dao.mysql.SchemaDAOImpl.java

@Override
public Schema getSchema(String schemaSetIdentifier, String schemaFileName, boolean workingCopy) {
    String sql = "select * from T_SCHEMA as S left join T_SCHEMA_SET as SS on (S.SCHEMA_SET_ID=SS.SCHEMA_SET_ID) "
            + "where SS.IDENTIFIER = :schemaSetIdentifier and SS.WORKING_COPY = :workingCopy AND S.FILENAME = :schemaFileName";
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("schemaSetIdentifier", schemaSetIdentifier);
    parameters.put("schemaFileName", schemaFileName);
    parameters.put("workingCopy", workingCopy);

    Schema result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<Schema>() {
        @Override/*from   w  ww.  ja v a  2 s.  c  o  m*/
        public Schema mapRow(ResultSet rs, int rowNum) throws SQLException {
            Schema schema = new Schema();
            schema.setId(rs.getInt("S.SCHEMA_ID"));
            schema.setFileName(rs.getString("S.FILENAME"));
            schema.setContinuityId(rs.getString("S.CONTINUITY_ID"));
            schema.setRegStatus(RegStatus.fromString(rs.getString("S.REG_STATUS")));
            schema.setWorkingCopy(rs.getBoolean("S.WORKING_COPY"));
            schema.setWorkingUser(rs.getString("S.WORKING_USER"));
            schema.setDateModified(rs.getTimestamp("S.DATE_MODIFIED"));
            schema.setUserModified(rs.getString("S.USER_MODIFIED"));
            schema.setComment(rs.getString("S.COMMENT"));
            schema.setCheckedOutCopyId(rs.getInt("S.CHECKEDOUT_COPY_ID"));
            schema.setSchemaSetId(rs.getInt("S.SCHEMA_SET_ID"));
            schema.setOtherDocument(rs.getBoolean("S.OTHER_DOCUMENT"));
            return schema;
        }
    });
    return result;
}

From source file:eionet.meta.dao.mysql.SchemaDAOImpl.java

@Override
public Schema getRootLevelSchema(String schemaFileName, boolean workingCopy) {
    String sql = "select * from T_SCHEMA as S where S.SCHEMA_SET_ID is NULL AND "
            + "S.WORKING_COPY = :workingCopy AND S.FILENAME = :schemaFileName";

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("schemaFileName", schemaFileName);
    parameters.put("workingCopy", workingCopy);

    Schema result = getNamedParameterJdbcTemplate().queryForObject(sql, parameters, new RowMapper<Schema>() {
        @Override// w w  w.  j av  a 2s .c  o  m
        public Schema mapRow(ResultSet rs, int rowNum) throws SQLException {
            Schema schema = new Schema();
            schema.setId(rs.getInt("S.SCHEMA_ID"));
            schema.setFileName(rs.getString("S.FILENAME"));
            schema.setContinuityId(rs.getString("S.CONTINUITY_ID"));
            schema.setRegStatus(RegStatus.fromString(rs.getString("S.REG_STATUS")));
            schema.setWorkingCopy(rs.getBoolean("S.WORKING_COPY"));
            schema.setWorkingUser(rs.getString("S.WORKING_USER"));
            schema.setDateModified(rs.getTimestamp("S.DATE_MODIFIED"));
            schema.setUserModified(rs.getString("S.USER_MODIFIED"));
            schema.setComment(rs.getString("S.COMMENT"));
            schema.setCheckedOutCopyId(rs.getInt("S.CHECKEDOUT_COPY_ID"));
            schema.setSchemaSetId(rs.getInt("S.SCHEMA_SET_ID"));
            schema.setOtherDocument(rs.getBoolean("S.OTHER_DOCUMENT"));
            return schema;
        }
    });
    return result;
}

From source file:de.static_interface.reallifeplugin.module.corporation.database.table.CorpsTable.java

@Override
public CorpRow[] deserialize(ResultSet rs) throws SQLException {
    int rowcount = 0;
    if (rs.last()) {
        rowcount = rs.getRow();/*  w  w w  .j  a  v a2 s .c  o m*/
        rs.beforeFirst();
    }

    CorpRow[] rows = new CorpRow[rowcount];
    int i = 0;

    while (rs.next()) {
        CorpRow row = new CorpRow();
        if (hasColumn(rs, "id")) {
            row.id = rs.getInt("id");
        }
        if (hasColumn(rs, "balance")) {
            row.balance = rs.getDouble("balance");
        }
        if (hasColumn(rs, "base_id")) {
            row.baseId = rs.getString("base_id");
        }
        if (hasColumn(rs, "base_world")) {
            row.baseWorld = rs.getString("base_world");
        }
        if (hasColumn(rs, "ceo_uuid")) {
            row.ceoUniqueId = UUID.fromString(rs.getString("ceo_uuid"));
        }
        if (hasColumn(rs, "corp_name")) {
            row.corpName = rs.getString("corp_name");
        }
        if (hasColumn(rs, "isdeleted")) {
            row.isDeleted = rs.getBoolean("isdeleted");
        }
        if (hasColumn(rs, "tag")) {
            row.tag = rs.getString("tag");
        }
        if (hasColumn(rs, "time")) {
            row.time = rs.getLong("time");
        }
        rows[i] = row;
        i++;
    }
    return rows;
}

From source file:com.alfaariss.oa.authentication.remote.aselect.idp.storage.jdbc.IDPJDBCStorage.java

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getIDP(java.lang.Object, java.lang.String)
 *//*from   w w w. ja  v a 2s .co  m*/
public IIDP getIDP(Object id, String type) throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    ASelectIDP oASelectIDP = null;
    try {
        connection = _dataSource.getConnection();

        StringBuffer sbSelect = new StringBuffer(_querySelectAll);
        sbSelect.append(" AND ");
        sbSelect.append(type);
        sbSelect.append("=?");
        pSelect = connection.prepareStatement(sbSelect.toString());
        pSelect.setBoolean(1, true);
        pSelect.setObject(2, id);
        resultSet = pSelect.executeQuery();
        if (resultSet.next()) {
            oASelectIDP = new ASelectIDP(resultSet.getString(COLUMN_ID),
                    resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_SERVER_ID),
                    resultSet.getString(COLUMN_URL), resultSet.getInt(COLUMN_LEVEL),
                    resultSet.getBoolean(COLUMN_SIGNING), resultSet.getString(COLUMN_COUNTRY),
                    resultSet.getString(COLUMN_LANGUAGE), resultSet.getBoolean(COLUMN_ASYNCHRONOUS_LOGOUT),
                    resultSet.getBoolean(COLUMN_SYNCHRONOUS_LOGOUT),
                    resultSet.getBoolean(COLUMN_SEND_ARP_TARGET));
        }
    } catch (Exception e) {
        _logger.fatal("Internal error during retrieval of IDP with id: " + id, e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (pSelect != null)
                pSelect.close();
        } catch (Exception e) {
            _logger.error("Could not close select statement", e);
        }

        try {
            if (connection != null)
                connection.close();
        } catch (Exception e) {
            _logger.error("Could not close connection", e);
        }
    }
    return oASelectIDP;
}