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:eionet.meta.dao.mysql.SchemaDAOImpl.java

@Override
public List<Schema> getSchemas(List<Integer> ids) {

    int nameAttrId = getNameAttributeId();

    String sql = "select s.*, ss.IDENTIFIER, ss.REG_STATUS SS_REG_STATUS,"
            + "(select VALUE from ATTRIBUTE where M_ATTRIBUTE_ID = :nameAttrId and DATAELEM_ID = s.SCHEMA_ID "
            + "and PARENT_TYPE = :parentType limit 1 ) as SCHEMA_NAME_ATTR "
            + " from T_SCHEMA as s LEFT OUTER JOIN T_SCHEMA_SET as ss ON (s.schema_set_id = ss.schema_set_id) "
            + "where SCHEMA_ID in (:ids)";

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("ids", ids);
    params.put("parentType", DElemAttribute.ParentType.SCHEMA.toString());
    params.put("nameAttrId", nameAttrId);

    List<Schema> resultList = getNamedParameterJdbcTemplate().query(sql, params, new RowMapper<Schema>() {
        @Override//from w  w w  . j a v  a  2s . co  m
        public Schema mapRow(ResultSet rs, int rowNum) throws SQLException {
            Schema schema = new Schema();
            schema.setId(rs.getInt("SCHEMA_ID"));
            schema.setFileName(rs.getString("FILENAME"));
            schema.setSchemaSetId(rs.getInt("SCHEMA_SET_ID"));
            schema.setContinuityId(rs.getString("CONTINUITY_ID"));
            schema.setRegStatus(RegStatus.fromString(rs.getString("s.REG_STATUS")));
            schema.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
            schema.setWorkingUser(rs.getString("WORKING_USER"));
            schema.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
            schema.setUserModified(rs.getString("USER_MODIFIED"));
            schema.setComment(rs.getString("COMMENT"));
            schema.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
            schema.setSchemaSetIdentifier(rs.getString("IDENTIFIER"));
            schema.setSchemaSetRegStatus(RegStatus.fromString(rs.getString("SS_REG_STATUS")));
            schema.setNameAttribute(rs.getString("SCHEMA_NAME_ATTR"));
            schema.setOtherDocument(rs.getBoolean("OTHER_DOCUMENT"));
            return schema;
        }
    });

    return resultList;
}

From source file:de.lsvn.dao.UserDao.java

public List<User> getAllUsers() {
    connection = DbUtil.getConnection();
    List<User> users = new ArrayList<User>();
    try {//from  ww w  .  j  a va 2s .  c o  m
        Statement statement1 = connection.createStatement();
        ResultSet rs = statement1.executeQuery(
                "SELECT * FROM medicals JOIN (mitglieder JOIN adressen ON mitglieder.AdresseId = adressen.AId) ON mitglieder.Id = medicals.MId ORDER BY Nachname");
        while (rs.next()) {
            User user = new User();
            user.setUserid(rs.getInt("Id"));
            user.setFirstName(rs.getString("Vorname"));
            user.setLastName(rs.getString("Nachname"));
            user.setEmail(rs.getString("eMail"));
            user.setEmailOffice(rs.getString("eMailDienstlich"));
            user.setTelephone(rs.getString("Telefon"));
            user.setPhoneOffice(rs.getString("TelefonDienstlich"));
            user.setHandy(rs.getString("Handy"));
            user.setBirthday(rs.getString("Geburtstag"));
            user.setMembership(rs.getString("Mitgliedschaft"));
            user.setVoting(rs.getBoolean("Stimmrecht"));
            user.setLicense(rs.getBoolean("Scheinpilot"));
            user.setYouth(rs.getBoolean("Jugend"));
            user.setAhk(rs.getBoolean("AHK"));
            user.setMs(rs.getBoolean("MS"));
            user.setPlz(rs.getString("Postleitzahl"));
            user.setCity(rs.getString("Ort"));
            user.setCountry(rs.getString("Land"));
            user.setStreet(rs.getString("Strasse"));
            user.setMedFrom(rs.getString("gueltig_von"));
            user.setMedTo(rs.getString("gueltig_bis"));
            user.setSpecialStatus(rs.getString("Sonderstatus"));
            users.add(user);
        }
        DbUtil.closeResultSet(rs);
        DbUtil.closeStatement(statement1);
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DbUtil.closeConnection(connection);
    }

    return users;
}

From source file:com.sfs.whichdoctor.dao.ExamDAOImpl.java

/**
 * Load exam./*w  w w  .  ja  v a2 s  .  c  om*/
 *
 * @param rs the rs
 * @return the exam bean
 * @throws SQLException the sQL exception
 */
private ExamBean loadExam(final ResultSet rs) throws SQLException {

    ExamBean exam = new ExamBean();

    exam.setId(rs.getInt("ExamId"));
    exam.setGUID(rs.getInt("GUID"));
    exam.setReferenceGUID(rs.getInt("ReferenceGUID"));
    exam.setType(rs.getString("Type"));
    exam.setTrainingOrganisation(rs.getString("TrainingOrganisation"));
    exam.setTrainingProgram(rs.getString("TrainingProgram"));
    exam.setStatus(rs.getString("Status"));
    exam.setStatusLevel(rs.getString("StatusLevel"));
    try {
        exam.setDateSat(rs.getDate("DateSat"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage());
    }
    exam.setLocation(rs.getString("Location"));
    exam.setAwardedMarks(rs.getInt("AwardedMarks"));
    exam.setTotalMarks(rs.getInt("TotalMarks"));

    exam.setActive(rs.getBoolean("Active"));
    try {
        exam.setCreatedDate(rs.getTimestamp("CreatedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading CreatedDate: " + sqe.getMessage());
    }
    exam.setCreatedBy(rs.getString("CreatedBy"));
    try {
        exam.setModifiedDate(rs.getTimestamp("ModifiedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading ModifiedDate: " + sqe.getMessage());
    }
    exam.setModifiedBy(rs.getString("ModifiedBy"));
    try {
        exam.setExportedDate(rs.getTimestamp("ExportedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading ExportedDate: " + sqe.getMessage());
    }
    exam.setExportedBy(rs.getString("ExportedBy"));

    return exam;
}

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

/**
 * {@inheritDoc}/*from ww  w. j av  a 2 s  .c  o m*/
 * @since 3.1.2
 */
@Override
public List<FxScriptSchedule> loadScriptSchedules(Connection con, FxEnvironmentImpl environment)
        throws FxLoadException {
    PreparedStatement ps = null;
    String sql;
    List<FxScriptSchedule> schedules = new ArrayList<FxScriptSchedule>(10);
    try {
        //             1   2     3      4       5         6         7             8            9
        sql = "SELECT ID,SCRIPT,SNAME,ACTIVE,STARTTIME,ENDTIME,REPEATINTERVAL,REPEATTIMES,CRONSTRING FROM "
                + TBL_SCRIPT_SCHEDULES + " ORDER BY SCRIPT";
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs != null && rs.next()) {
            long id = rs.getLong(1);
            long scriptId = rs.getLong(2);
            String name = rs.getString(3);
            if (rs.wasNull())
                name = "";
            boolean active = rs.getBoolean(4);
            java.util.Date startTime = new java.util.Date(rs.getTimestamp(5).getTime());
            Timestamp endts = rs.getTimestamp(6);
            final java.util.Date endTime;
            if (rs.wasNull())
                endTime = null;
            else
                endTime = new java.util.Date(endts.getTime());
            long repeatInterval = rs.getLong(7);
            int repeatTimes = rs.getInt(8);
            String cronString = rs.getString(9);
            if (rs.wasNull())
                cronString = "";
            schedules.add(new FxScriptSchedule(id, scriptId, name, active, startTime, endTime, repeatInterval,
                    repeatTimes, cronString));
        }
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.scripting.schedule.load.failed", -1, exc.getMessage());
    } finally {
        Database.closeObjects(GenericEnvironmentLoader.class, null, ps);
    }
    return schedules;
}

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

@Override
public NodesList getNodeChildren(final VospaceId identifier, final boolean searchDeep /*always false*/,
        final boolean includeDeleted /*not used*/, final int start, final int count) {
    if (identifier.getNodePath().isRoot(false)) {
        String deletedCondition = includeDeleted ? "" : "nodes.`deleted` = 0 AND ";
        return DbPoolServlet.goSql("GetNodeChildren root request",
                "SELECT SQL_CALC_FOUND_ROWS containers.container_name as container, nodes.rev, nodes.deleted, nodes.mtime, nodes.size, nodes.mimetype, nodes.type "
                        + "FROM nodes JOIN containers ON nodes.container_id = containers.container_id JOIN user_identities ON containers.user_id = user_identities.user_id "
                        + "WHERE " + deletedCondition
                        + "`parent_node_id` is NULL AND `identity` = ? AND `container_name` <> '' order by container "
                        + ((count > 0) ? " limit ?, ?" : ""),
                new SqlWorker<NodesList>() {
                    @Override//from   w w w. ja  v a2s  .com
                    public NodesList go(Connection conn, PreparedStatement stmt) throws SQLException {
                        ArrayList<Node> result = new ArrayList<Node>();
                        int countRows = 0;

                        stmt.setString(1, owner);

                        if (count > 0) {
                            stmt.setInt(2, start);
                            stmt.setInt(3, count);
                        }

                        ResultSet rs = stmt.executeQuery();
                        while (rs.next()) {
                            try {
                                VospaceId id = new VospaceId(new NodePath(rs.getString("container")));
                                id.getNodePath()
                                        .setEnableAppContainer(identifier.getNodePath().isEnableAppContainer());

                                NodeInfo info = new NodeInfo();
                                info.setRevision(rs.getInt("rev"));
                                info.setDeleted(rs.getBoolean("deleted"));
                                info.setMtime(new Date(rs.getTimestamp("mtime").getTime()));
                                info.setSize(rs.getLong("size"));
                                info.setContentType(rs.getString("mimetype"));

                                Node newNode = NodeFactory.createNode(id, owner,
                                        NodeType.valueOf(rs.getString("type")));
                                newNode.setNodeInfo(info);

                                result.add(newNode);
                            } catch (URISyntaxException e) {
                                logger.error("Error in child URI: " + e.getMessage());
                            }
                        }

                        ResultSet resSet = conn.createStatement().executeQuery("SELECT FOUND_ROWS();");
                        resSet.next();
                        countRows = resSet.getInt(1);

                        return new NodesList(result, countRows);
                    }
                });
    } else {
        String deletedCondition = includeDeleted ? "" : "nodes.`deleted` = 0 AND ";
        String request = "SELECT SQL_CALC_FOUND_ROWS containers.container_name as container, nodes.path, nodes.rev, nodes.deleted, nodes.mtime, nodes.size, nodes.mimetype, nodes.type "
                + "FROM nodes JOIN containers ON nodes.container_id = containers.container_id "
                + "JOIN user_identities ON containers.user_id = user_identities.user_id "
                + "JOIN nodes b ON nodes.parent_node_id = b.node_id " + "WHERE " + deletedCondition
                + "containers.container_name = ? AND b.`path` = ? AND `identity` = ? order by path "
                + ((count > 0) ? " limit ?, ?" : "");

        return DbPoolServlet.goSql("GetNodeChildren request", request, new SqlWorker<NodesList>() {
            @Override
            public NodesList go(Connection conn, PreparedStatement stmt) throws SQLException {
                ArrayList<Node> result = new ArrayList<Node>();
                int countRows = 0;

                stmt.setString(1, identifier.getNodePath().getContainerName());
                stmt.setString(2, identifier.getNodePath().getNodeRelativeStoragePath());
                stmt.setString(3, owner);

                if (count > 0) {
                    stmt.setInt(4, start);
                    stmt.setInt(5, count);
                }

                ResultSet rs = stmt.executeQuery();
                while (rs.next()) {
                    try {
                        VospaceId id = new VospaceId(
                                new NodePath(rs.getString("container") + "/" + rs.getString("path")));
                        id.getNodePath().setEnableAppContainer(identifier.getNodePath().isEnableAppContainer());

                        NodeInfo info = new NodeInfo();
                        info.setRevision(rs.getInt("rev"));
                        info.setDeleted(rs.getBoolean("deleted"));
                        info.setMtime(new Date(rs.getTimestamp("mtime").getTime()));
                        info.setSize(rs.getLong("size"));
                        info.setContentType(rs.getString("mimetype"));

                        Node newNode = NodeFactory.createNode(id, owner,
                                NodeType.valueOf(rs.getString("type")));
                        newNode.setNodeInfo(info);

                        result.add(newNode);
                    } catch (URISyntaxException e) {
                        logger.error("Error in child URI: " + e.getMessage());
                    }
                }

                ResultSet resSet = conn.createStatement().executeQuery("SELECT FOUND_ROWS();");
                resSet.next();
                countRows = resSet.getInt(1);

                return new NodesList(result, countRows);
            }
        });
    }
}

From source file:com.alfaariss.oa.engine.requestor.jdbc.JDBCRequestorPool.java

/**
 * Creates the object by reading information from JDBC.
 * <br>//from  w w w .j av  a2 s  .  com
 * @param oDataSource JDBC resource
 * @param oResultSet containing a row from the pool table
 * @param sPoolsTable the pool table name
 * @param sRequestorsTable the requestors table name
 * @param sRequestorPropertiesTable the requestor properties table name
 * @param sAuthenticationTable the authentication table name
 * @param sPoolPropertiesTable the requestor pool properties table name
 * @throws RequestorException when creation fails
 */
public JDBCRequestorPool(ResultSet oResultSet, DataSource oDataSource, String sPoolsTable,
        String sRequestorsTable, String sRequestorPropertiesTable, String sAuthenticationTable,
        String sPoolPropertiesTable) throws RequestorException {
    try {
        _logger = LogFactory.getLog(JDBCRequestorPool.class);

        _sID = oResultSet.getString(COLUMN_ID);
        _sFriendlyName = oResultSet.getString(COLUMN_FRIENDLYNAME);
        if (_sFriendlyName == null) {
            StringBuffer sbWarn = new StringBuffer("No '");
            sbWarn.append(COLUMN_FRIENDLYNAME);
            sbWarn.append("' available for requestorpool with id: ");
            sbWarn.append(_sID);
            _logger.error(sbWarn.toString());
            throw new RequestorException(SystemErrors.ERROR_RESOURCE_RETRIEVE);
        }

        _bEnabled = oResultSet.getBoolean(COLUMN_ENABLED);
        _bForcedAuthenticate = oResultSet.getBoolean(COLUMN_FORCED);
        _sAttributeReleasePolicyID = oResultSet.getString(COLUMN_RELEASEPOLICY);
        _sPreAuthorizationProfileID = oResultSet.getString(COLUMN_PREAUTHORIZATION);
        _sPostAuthorizationProfileID = oResultSet.getString(COLUMN_POSTAUTHORIZATIE);

        addAuthenticationProfiles(oDataSource, sAuthenticationTable);

        addRequestors(oDataSource, sPoolsTable, sRequestorsTable, sRequestorPropertiesTable);

        addProperties(oDataSource, sPoolPropertiesTable);
    } catch (SQLException e) {
        _logger.error("Can not read pool from database", e);
        throw new RequestorException(SystemErrors.ERROR_RESOURCE_RETRIEVE);
    } catch (RequestorException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Internal error during pool object creation", e);
        throw new RequestorException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:it.anyplace.sync.repository.repo.SqlRepository.java

private FileInfo readFileInfo(ResultSet resultSet) throws SQLException {
    String folder = resultSet.getString("folder"), path = resultSet.getString("path");
    FileType fileType = FileType.valueOf(resultSet.getString("file_type"));
    Date lastModified = new Date(resultSet.getLong("last_modified"));
    List<Version> versionList = Collections
            .singletonList(new Version(resultSet.getLong("version_id"), resultSet.getLong("version_value")));
    boolean isDeleted = resultSet.getBoolean("is_deleted");
    FileInfo.Builder builder = FileInfo.newBuilder().setFolder(folder).setPath(path)
            .setLastModified(lastModified).setVersionList(versionList).setDeleted(isDeleted);
    if (equal(fileType, FileType.DIRECTORY)) {
        return builder.setTypeDir().build();
    } else {/*from   w ww  . j a  va  2 s. com*/
        return builder.setTypeFile().setSize(resultSet.getLong("size")).setHash(resultSet.getString("hash"))
                .build();
    }
}

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

/**
 * {@inheritDoc}/*from   w w w .  j  a  v  a  2 s  .c  om*/
 */
@Override
public Mandator[] loadMandators(Connection con) throws FxLoadException {

    PreparedStatement ps = null;
    try {
        // Load all mandators within the system
        ps = con.prepareStatement(
                "SELECT ID,NAME,METADATA,IS_ACTIVE,CREATED_BY,CREATED_AT,MODIFIED_BY,MODIFIED_AT FROM "
                        + TBL_MANDATORS + " order by upper(NAME)");
        ResultSet rs = ps.executeQuery();
        ArrayList<Mandator> result = new ArrayList<Mandator>(20);
        while (rs != null && rs.next()) {
            int metaDataId = rs.getInt(3);
            if (rs.wasNull()) {
                metaDataId = -1;
            }
            result.add(new Mandator(rs.getInt(1), rs.getString(2), metaDataId, rs.getBoolean(4),
                    LifeCycleInfoImpl.load(rs, 5, 6, 7, 8)));
        }
        // return the result
        return result.toArray(new Mandator[result.size()]);
    } catch (SQLException se) {
        FxLoadException le = new FxLoadException(se.getMessage(), se);
        LOG.error(le);
        throw le;
    } finally {
        Database.closeObjects(GenericEnvironmentLoader.class, null, ps);
    }
}

From source file:com.googlecode.fascinator.portal.HouseKeeper.java

/**
 * Rebuild the in-memory list of actions from the database.
 * /*www .  j ava2 s . c  o m*/
 */
private void syncActionList() {
    // Purge current list
    actions = new ArrayList<UserAction>();
    try {
        // Prepare our query
        PreparedStatement sql = dbConnection()
                .prepareCall("SELECT * FROM " + NOTIFICATIONS_TABLE + " ORDER BY block DESC, id");
        // Run the query
        ResultSet result = sql.executeQuery();
        // Build our list
        while (result.next()) {
            UserAction ua = new UserAction();
            ua.id = result.getInt("id");
            ua.block = result.getBoolean("block");
            ua.message = result.getString("message");
            ua.date = new Date(result.getTimestamp("datetime").getTime());
            actions.add(ua);
        }
        // Release the resultset
        close(result);
        close(sql);
    } catch (SQLException ex) {
        log.error("Error accessing database: ", ex);
    }
}

From source file:ResultSetIterator.java

/**
 * Convert a <code>ResultSet</code> column into an object.  Simple 
 * implementations could just call <code>rs.getObject(index)</code> while
 * more complex implementations could perform type manipulation to match 
 * the column's type to the bean property type.
 * /*from   w  w  w .jav a  2 s . c  om*/
 * <p>
 * This implementation calls the appropriate <code>ResultSet</code> getter 
 * method for the given property type to perform the type conversion.  If 
 * the property type doesn't match one of the supported 
 * <code>ResultSet</code> types, <code>getObject</code> is called.
 * </p>
 * 
 * @param rs The <code>ResultSet</code> currently being processed.  It is
 * positioned on a valid row before being passed into this method.
 * 
 * @param index The current column index being processed.
 * 
 * @param propType The bean property type that this column needs to be
 * converted into.
 * 
 * @throws SQLException if a database access error occurs
 * 
 * @return The object from the <code>ResultSet</code> at the given column
 * index after optional type processing or <code>null</code> if the column
 * value was SQL NULL.
 */
protected Object processColumn(ResultSet rs, int index, Class propType) throws SQLException {

    if (!propType.isPrimitive() && rs.getObject(index) == null) {
        return null;
    }

    if (propType.equals(String.class)) {
        return rs.getString(index);

    } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) {
        return new Integer(rs.getInt(index));

    } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) {
        return new Boolean(rs.getBoolean(index));

    } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) {
        return new Long(rs.getLong(index));

    } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) {
        return new Double(rs.getDouble(index));

    } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) {
        return new Float(rs.getFloat(index));

    } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) {
        return new Short(rs.getShort(index));

    } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) {
        return new Byte(rs.getByte(index));

    } else if (propType.equals(Timestamp.class)) {
        return rs.getTimestamp(index);

    } else {
        return rs.getObject(index);
    }

}