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:com.flexive.ejb.beans.UserGroupEngineBean.java

/**
 * {@inheritDoc}/*from   w ww  .  java  2  s  . co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public UserGroup loadMandatorGroup(long mandatorId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String sql = "SELECT ID,MANDATOR,NAME,COLOR,AUTOMANDATOR,ISSYSTEM FROM " + TBL_USERGROUPS
            + " WHERE AUTOMANDATOR=" + mandatorId;

    try {

        // Obtain a database connection
        con = Database.getDbConnection();

        // Create the new workflow instance
        stmt = con.createStatement();

        // Build statement
        ResultSet rs = stmt.executeQuery(sql);

        // Does the group exist at all?
        if (rs == null || !rs.next())
            throw new FxNotFoundException("ex.account.group.notFound.id", mandatorId);
        long autoMandator = rs.getLong(5);
        if (rs.wasNull())
            autoMandator = -1;
        return new UserGroup(rs.getLong(1), rs.getLong(2), autoMandator, rs.getBoolean(6), rs.getString(3),
                rs.getString(4));
    } catch (SQLException exc) {
        FxLoadException de = new FxLoadException(exc, "ex.usergroup.sqlError", exc.getMessage(), sql);
        LOG.error(de);
        throw de;
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

From source file:CSVWriter.java

private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException {

    String value = "";

    switch (colType) {
    case Types.BIT:
    case Types.JAVA_OBJECT:
        value = handleObject(rs.getObject(colIndex));
        break;/*from   www. j  av a 2  s  .  c  om*/
    case Types.BOOLEAN:
        boolean b = rs.getBoolean(colIndex);
        value = Boolean.valueOf(b).toString();
        break;
    case NCLOB: // todo : use rs.getNClob
    case Types.CLOB:
        Clob c = rs.getClob(colIndex);
        if (c != null) {
            value = read(c);
        }
        break;
    case Types.BIGINT:
        value = handleLong(rs, colIndex);
        break;
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.REAL:
    case Types.NUMERIC:
        value = handleBigDecimal(rs.getBigDecimal(colIndex));
        break;
    case Types.INTEGER:
    case Types.TINYINT:
    case Types.SMALLINT:
        value = handleInteger(rs, colIndex);
        break;
    case Types.DATE:
        value = handleDate(rs, colIndex);
        break;
    case Types.TIME:
        value = handleTime(rs.getTime(colIndex));
        break;
    case Types.TIMESTAMP:
        value = handleTimestamp(rs.getTimestamp(colIndex));
        break;
    case NVARCHAR: // todo : use rs.getNString
    case NCHAR: // todo : use rs.getNString
    case LONGNVARCHAR: // todo : use rs.getNString
    case Types.LONGVARCHAR:
    case Types.VARCHAR:
    case Types.CHAR:
        value = rs.getString(colIndex);
        break;
    default:
        value = "";
    }

    if (value == null) {
        value = "";
    }

    return value;

}

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

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getAll()
 *///from   ww  w .  ja  v a  2  s .co  m
public List<IIDP> getAll() throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    List<IIDP> listIDPs = new Vector<IIDP>();

    IMetadataProviderManager oMPM = MdMgrManager.getInstance().getMetadataProviderManager(_sId);

    try {
        boolean dateLastModifiedExists = true;

        connection = _dataSource.getConnection();

        pSelect = connection.prepareStatement(_sQuerySelectAll);
        pSelect.setBoolean(1, true);
        resultSet = pSelect.executeQuery();
        while (resultSet.next()) {
            boolean bACSIndex = resultSet.getBoolean(COLUMN_ACS_INDEX);

            Boolean boolAllowCreate = null;
            String sAllowCreate = resultSet.getString(COLUMN_ALLOW_CREATE);
            if (sAllowCreate != null) {
                boolean bAllowCreate = resultSet.getBoolean(COLUMN_ALLOW_CREATE);
                boolAllowCreate = new Boolean(bAllowCreate);
            }

            boolean bScoping = resultSet.getBoolean(COLUMN_SCOPING);
            boolean bNameIDPolicy = resultSet.getBoolean(COLUMN_NAMEIDPOLICY);
            boolean bAvoidSubjectConfirmation = resultSet.getBoolean(COLUMN_AVOID_SUBJCONF);
            boolean bDisableSSOForIDP = resultSet.getBoolean(COLUMN_DISABLE_SSO);

            // Implement date_last_modified column as optional
            Date dLastModified = null;
            if (dateLastModifiedExists) {
                try {
                    dLastModified = resultSet.getTimestamp(COLUMN_DATELASTMODIFIED);
                } catch (Exception e) {
                    _oLogger.info("No " + COLUMN_DATELASTMODIFIED + " column found; ignoring.");
                    dateLastModifiedExists = false;
                }
            }

            SAML2IDP idp = new SAML2IDP(resultSet.getString(COLUMN_ID), resultSet.getBytes(COLUMN_SOURCEID),
                    resultSet.getString(COLUMN_FRIENDLYNAME), resultSet.getString(COLUMN_METADATA_FILE),
                    resultSet.getString(COLUMN_METADATA_URL), resultSet.getInt(COLUMN_METADATA_TIMEOUT),
                    bACSIndex, boolAllowCreate, bScoping, bNameIDPolicy,
                    resultSet.getString(COLUMN_NAMEIDFORMAT), bAvoidSubjectConfirmation, bDisableSSOForIDP,
                    dLastModified, oMPM.getId());
            listIDPs.add(idp);
        }
    } catch (Exception e) {
        _oLogger.fatal("Internal error during retrieval of all IDPs", e);
        throw new OAException(SystemErrors.ERROR_INTERNAL);
    } finally {
        try {
            if (pSelect != null)
                pSelect.close();
        } catch (Exception e) {
            _oLogger.error("Could not close select statement", e);
        }

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

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

/**
 * {@inheritDoc}/*w  w w.j  a va 2s  .  c om*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<UserGroup> loadAll(long mandatorId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String sql = null;
    try {

        // Obtain a database connection
        con = Database.getDbConnection();

        // Create the new workflow instance
        stmt = con.createStatement();

        //            1  2        3    4     5            6
        sql = "SELECT ID,MANDATOR,NAME,COLOR,AUTOMANDATOR,ISSYSTEM FROM " + TBL_USERGROUPS +
        // Never display the dummy NULL group
                " WHERE ID!=" + UserGroup.GROUP_NULL;
        if (mandatorId != -1)
            sql += " AND (MANDATOR=" + mandatorId + " or ID in (" + UserGroup.GROUP_EVERYONE + ","
                    + UserGroup.GROUP_OWNER + "))";
        sql += " ORDER BY MANDATOR,NAME";

        ResultSet rs = stmt.executeQuery(sql);

        // Process resultset
        final List<UserGroup> result = new ArrayList<UserGroup>();
        while (rs != null && rs.next()) {
            long autoMandator = rs.getLong(5);
            if (rs.wasNull())
                autoMandator = -1;
            result.add(new UserGroup(rs.getLong(1), rs.getLong(2), autoMandator, rs.getBoolean(6),
                    rs.getString(3), rs.getString(4)));
        }

        // Sanity check
        if (indexOfSelectableObject(result, UserGroup.GROUP_EVERYONE) == -1
                || indexOfSelectableObject(result, UserGroup.GROUP_OWNER) == -1) {
            FxLoadException le = new FxLoadException("ex.usergroup.oneOfSystemGroupsIsMissing");
            LOG.fatal(le);
            throw le;
        }

        return result;
    } catch (SQLException exc) {
        FxLoadException de = new FxLoadException(exc, "ex.usergroup.sqlError", exc.getMessage(), sql);
        LOG.error(de);
        throw de;
    } finally {
        Database.closeObjects(UserGroupEngineBean.class, con, stmt);
    }
}

From source file:net.hydromatic.optiq.impl.jdbc.JdbcSchema.java

RelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName, String schemaName,
        String tableName) throws SQLException {
    final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null);

    // Temporary type factory, just for the duration of this method. Allowable
    // because we're creating a proto-type, not a type; before being used, the
    // proto-type will be copied into a real type factory.
    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl();
    final RelDataTypeFactory.FieldInfoBuilder fieldInfo = typeFactory.builder();
    while (resultSet.next()) {
        final String columnName = resultSet.getString(4);
        final int dataType = resultSet.getInt(5);
        final int size = resultSet.getInt(7);
        final int scale = resultSet.getInt(9);
        RelDataType sqlType = sqlType(typeFactory, dataType, size, scale);
        boolean nullable = resultSet.getBoolean(11);
        fieldInfo.add(columnName, sqlType).nullable(nullable);
    }/*from   w ww.j a  v a2 s.  com*/
    resultSet.close();
    return RelDataTypeImpl.proto(fieldInfo.build());
}

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

/**
 * Returns a boolean object with the value of the account enabled field.
 * @param id the user id//  www .  j a v a  2 s .  c  o m
 * @return TRUE if account enabled or null if no account found
 * @throws UserException if retrieval failed
 */
private Boolean isAccountEnabled(String id) throws UserException {
    Boolean boolReturn = null;
    PreparedStatement oPreparedStatement = null;
    ResultSet oResultSet = null;
    Connection oConnection = null;
    try {
        oConnection = _oDataSource.getConnection();
        oPreparedStatement = oConnection.prepareStatement(_sAccountEnabledSelect);
        oPreparedStatement.setString(1, id);
        oResultSet = oPreparedStatement.executeQuery();
        if (!oResultSet.next())
            return null; // user unknown

        boolReturn = oResultSet.getBoolean(COLUMN_ACCOUNT_ENABLED);
    } catch (SQLException e) {
        _logger.error("Could not retrieve account enabled for user with id: " + id, e);
        throw new UserException(SystemErrors.ERROR_RESOURCE_RETRIEVE);
    } catch (Exception e) {
        _logger.error("Could not retrieve account information for account with id: " + id, 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 boolReturn;
}

From source file:mupomat.controller.ObradaKorisnik.java

public List<Korisnik> dohvatiNeaktivnogKorisnika(String uvjet) {
    List<Korisnik> lista = new ArrayList<>();
    try {/*from ww  w.  j  ava 2  s  .  co  m*/
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = veza.prepareStatement(
                "select a.sifra,a.datumregistracije,a.korisnickoime,a.uloga,a.aktivan, b.* from korisnik a inner join osoba b on a.oib=b.oib where b.ime like  ? and aktivan=0");
        izraz.setString(1, "%" + uvjet + "%");
        //            izraz.setString(2, "%" + uvjet + "%");

        ResultSet rs = izraz.executeQuery();
        Korisnik entitet = null;
        while (rs.next()) {
            //System.out.println("evo me");
            entitet = new Korisnik();
            entitet.setSifra(rs.getInt("sifra"));
            entitet.setIme(rs.getString("ime"));
            entitet.setPrezime(rs.getString("prezime"));
            entitet.setOib(rs.getString("oib"));
            entitet.setEmail(rs.getString("email"));
            entitet.setDatumRegistracije(new Date(rs.getTimestamp("datumregistracije").getTime()));
            entitet.setKorisnickoIme(rs.getString("korisnickoime"));
            entitet.setUloga(rs.getString("uloga"));
            entitet.setAktivan(rs.getBoolean("aktivan"));

            lista.add(entitet);

        }
        rs.close();
        izraz.close();
        veza.close();
    } catch (Exception e) {

        e.printStackTrace();
        return null;
    }

    return lista;
}

From source file:mupomat.controller.ObradaKorisnik.java

@Override
public List<Korisnik> dohvatiIzBaze(String uvjet) {
    List<Korisnik> lista = new ArrayList<>();
    try {// w  w  w. j  a  v  a  2 s .c  o  m
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = veza.prepareStatement(
                "select a.sifra,a.datumregistracije,a.korisnickoime,a.uloga,a.aktivan, b.* from korisnik a inner join osoba b on a.oib=b.oib where b.ime like  ? and aktivan=1");
        izraz.setString(1, "%" + uvjet + "%");
        //            izraz.setString(2, "%" + uvjet + "%");

        ResultSet rs = izraz.executeQuery();
        Korisnik entitet = null;
        while (rs.next()) {
            //System.out.println("evo me");
            entitet = new Korisnik();
            entitet.setSifra(rs.getInt("sifra"));
            entitet.setIme(rs.getString("ime"));
            entitet.setPrezime(rs.getString("prezime"));
            entitet.setOib(rs.getString("oib"));
            entitet.setEmail(rs.getString("email"));
            entitet.setDatumRegistracije(new Date(rs.getTimestamp("datumregistracije").getTime()));
            entitet.setKorisnickoIme(rs.getString("korisnickoime"));
            entitet.setUloga(rs.getString("uloga"));
            entitet.setAktivan(rs.getBoolean("aktivan"));

            lista.add(entitet);

        }
        rs.close();
        izraz.close();
        veza.close();
    } catch (Exception e) {

        e.printStackTrace();
        return null;
    }

    return lista;
}

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

/**
 * Load the specialty bean from the resultset.
 *
 * @param rs the rs//from  ww w.ja  v  a2s . co  m
 * @return the specialty bean
 * @throws SQLException the sQL exception
 */
private SpecialtyBean loadSpecialty(final ResultSet rs) throws SQLException {

    SpecialtyBean specialty = new SpecialtyBean();

    specialty.setId(rs.getInt("SpecialtyId"));
    specialty.setGUID(rs.getInt("GUID"));
    specialty.setReferenceGUID(rs.getInt("ReferenceGUID"));
    specialty.setTrainingOrganisation(rs.getString("TrainingOrganisation"));
    specialty.setTrainingProgram(rs.getString("TrainingProgram"));
    specialty.setTrainingProgramYear(rs.getInt("TrainingProgramYear"));
    specialty.setMemo(rs.getString("Memo"));
    specialty.setStatus(rs.getString("SpecialtyStatus"));
    specialty.setIsbRole(1, rs.getString("ISBRole"));
    specialty.setIsbRole(2, rs.getString("SecondISBRole"));
    specialty.setIsbRole(3, rs.getString("ThirdISBRole"));

    specialty.setActive(rs.getBoolean("Active"));
    try {
        specialty.setCreatedDate(rs.getTimestamp("CreatedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error parsing CreatedDate: " + sqe.getMessage());
    }
    specialty.setCreatedBy(rs.getString("CreatedBy"));
    try {
        specialty.setModifiedDate(rs.getTimestamp("ModifiedDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error parsing ModifiedDate: " + sqe.getMessage());
    }
    specialty.setModifiedBy(rs.getString("ModifiedBy"));

    return specialty;
}

From source file:info.raack.appliancelabeler.data.JDBCDatabase.java

@Override
public GenericStateTransition getAnonymousApplianceStateTransitionById(final int transitionId) {
    return jdbcTemplate.queryForObject("select * from appliance_state_transitions where id = ?",
            new Object[] { transitionId }, new RowMapper<GenericStateTransition>() {

                @Override// ww  w  . jav a  2s  . c o  m
                public GenericStateTransition mapRow(ResultSet rs, int arg1) throws SQLException {
                    return new GenericStateTransition(transitionId, null, rs.getInt("detection_algorithm"),
                            rs.getBoolean("start_on"), rs.getLong("time"));
                }
            });
}