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:cc.cicadabear.security.infrastructure.jdbc.OauthClientDetailsRowMapper.java

@Override
public OauthClientDetails mapRow(ResultSet rs, int i) throws SQLException {
    OauthClientDetails clientDetails = new OauthClientDetails();

    clientDetails.clientId(rs.getString("client_id"));
    clientDetails.resourceIds(rs.getString("resource_ids"));
    clientDetails.clientSecret(rs.getString("client_secret"));

    clientDetails.scope(rs.getString("scope"));
    clientDetails.authorizedGrantTypes(rs.getString("authorized_grant_types"));
    clientDetails.webServerRedirectUri(rs.getString("web_server_redirect_uri"));

    clientDetails.authorities(rs.getString("authorities"));
    clientDetails.accessTokenValidity(getInteger(rs, "access_token_validity"));
    clientDetails.refreshTokenValidity(getInteger(rs, "refresh_token_validity"));

    clientDetails.additionalInformation(rs.getString("additional_information"));
    clientDetails.createTime(rs.getTimestamp("create_time").toLocalDateTime());
    clientDetails.archived(rs.getBoolean("archived"));

    clientDetails.trusted(rs.getBoolean("trusted"));
    clientDetails.autoApprove(rs.getString("autoapprove"));

    return clientDetails;
}

From source file:bizlogic.Records.java

public static void list(Connection DBcon) throws IOException, ParseException, SQLException {

    Statement st;/*  ww w .  j a va2  s.c o m*/
    ResultSet rs = null;

    try {
        st = DBcon.createStatement();
        rs = st.executeQuery("SELECT userconf.log_list.sensor_id, " + "userconf.log_list.smpl_interval, "
                + "userconf.log_list.running, " + "userconf.log_list.name AS log_name, "
                + "userconf.log_list.log_id, " + "userconf.sensorlist.name AS sensor_name "
                + "FROM USERCONF.LOG_LIST " + "JOIN userconf.sensorlist "
                + "ON userconf.log_list.sensor_id=userconf.sensorlist.sensor_id");

    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Records.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    }

    try {
        FileWriter recordsFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/records.json");
        //BufferedWriter recordsFile = new BufferedWriter(_file);
        //recordsFile.write("");
        //recordsFile.flush(); 

        FileReader fr = new FileReader("/var/lib/tomcat8/webapps/ROOT/Records/records.json");
        BufferedReader br = new BufferedReader(fr);

        JSONObject Records = new JSONObject();

        int _total = 0;

        JSONArray recordList = new JSONArray();

        while (rs.next()) {

            String isRunningStr;

            JSONObject sensor_Obj = new JSONObject();

            int sensor_id = rs.getInt("sensor_id");
            sensor_Obj.put("sensor_id", sensor_id);

            String smpl_interval = rs.getString("smpl_interval");
            sensor_Obj.put("smpl_interval", smpl_interval);

            Boolean running = rs.getBoolean("running");
            if (running) {
                //System.out.print("1");
                isRunningStr = "ON";
            } else {
                //System.out.print("0");
                isRunningStr = "OFF";
            }
            sensor_Obj.put("running", isRunningStr);

            String log_name = rs.getString("log_name");
            sensor_Obj.put("log_name", log_name);

            String sensor_name = rs.getString("sensor_name");
            sensor_Obj.put("sensor_name", sensor_name);

            int log_id = rs.getInt("log_id");
            sensor_Obj.put("recid", log_id);

            recordList.add(sensor_Obj);
            _total++;

        }

        rs.close();

        Records.put("total", _total);
        Records.put("records", recordList);

        recordsFile.write(Records.toJSONString());
        recordsFile.flush();

        recordsFile.close();

        System.out.print(Records.toJSONString());
        System.out.print(br.readLine());

    }

    catch (IOException ex) {
        Logger.getLogger(Records.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getAll()
 *///from   w w w .j ava  2  s .com
public List<IIDP> getAll() throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    List<IIDP> listIDPs = new Vector<IIDP>();
    try {
        connection = _dataSource.getConnection();

        pSelect = connection.prepareStatement(_querySelectAll);
        pSelect.setBoolean(1, true);
        resultSet = pSelect.executeQuery();
        while (resultSet.next()) {
            ASelectIDP idp = 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));
            listIDPs.add(idp);
        }
    } catch (Exception e) {
        _logger.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) {
            _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 listIDPs;
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public List<Object[]> searchSites(String titleSearch, Map<String, String> propsMap, String[] instructorIds,
        String insturctorType, boolean publishedOnly) {
    try {/* w w w .j a va  2  s.  c o  m*/
        if (titleSearch == null) {
            titleSearch = "";
        }
        titleSearch = "%" + titleSearch + "%";
        Object[] params = new Object[] { titleSearch };
        String query = "";
        final boolean noInstructors = instructorIds == null || instructorIds.length == 0;
        //either grab the simple site search based on title or the one that limits by instructor ids
        if (noInstructors) {
            query = getStatement("select.siteSearch");
        } else {
            if (DelegatedAccessConstants.ADVANCED_SEARCH_INSTRUCTOR_TYPE_MEMBER.equals(insturctorType)) {
                query = getStatement("select.siteSearchMembers");
            } else {
                //default is instructor search
                query = getStatement("select.siteSearchInstructors");
            }
            String inParams = "(";
            //to be on the safe side, I added oracle limit restriction, but hopefully no one is searching for
            //more than 1000 instructors
            for (int i = 0; i < instructorIds.length && i < ORACLE_IN_CLAUSE_SIZE_LIMIT; i++) {
                inParams += "'" + instructorIds[i].replace("'", "''") + "'";
                if (i < instructorIds.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query = query.replace("(:userIds)", inParams);
        }
        //add the site properties restrictions in the where clause
        if (propsMap != null && propsMap.size() > 0) {
            params = new Object[1 + (propsMap.size() * 2)];
            params[0] = titleSearch;
            int i = 1;
            for (Entry<String, String> entry : propsMap.entrySet()) {
                query += " " + getStatement("select.siteSearchPropWhere");
                params[i] = entry.getKey();
                i++;
                params[i] = entry.getValue();
                i++;
            }
        }
        if (publishedOnly) {
            query += " " + getStatement("select.siteSearchPublishedOnly");
        }

        return (List<Object[]>) getJdbcTemplate().query(query, params, new RowMapper() {

            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                if (noInstructors) {
                    return new Object[] { resultSet.getString("SITE_ID"), resultSet.getString("TITLE"),
                            resultSet.getBoolean("PUBLISHED") };
                } else {
                    return new Object[] { resultSet.getString("SITE_ID"), resultSet.getString("TITLE"),
                            resultSet.getBoolean("PUBLISHED"), resultSet.getString("USER_ID") };
                }
            }
        });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return new ArrayList<Object[]>();
    }
}

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

/**
 * Load online tool bean from the result set.
 *
 * @param rs the rs//from w  ww  .  j a  v  a  2 s.  com
 * @return the online tool bean
 * @throws SQLException the sQL exception
 */
private OnlineToolBean loadOnlineTool(final ResultSet rs) throws SQLException {

    OnlineToolBean onlineTool = new OnlineToolBean();

    onlineTool.setId(rs.getInt("OnlineToolId"));
    onlineTool.setReferenceGUID(rs.getInt("ReferenceGUID"));
    onlineTool.setRotationGUID(rs.getInt("RotationGUID"));
    onlineTool.setRotationOverridden(rs.getBoolean("RotationOverridden"));
    onlineTool.setName(rs.getString("Name"));
    onlineTool.setShortName(rs.getString("ShortName"));
    onlineTool.setCourse(rs.getString("Course"));
    onlineTool.setStatus(rs.getString("Status"));
    onlineTool.setYear(rs.getInt("Year"));
    onlineTool.setRotationName(rs.getString("RotationName"));

    try {
        onlineTool.setStartDate(rs.getTimestamp("StartDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading StartDate: " + sqe.getMessage());
    }

    try {
        onlineTool.setEndDate(rs.getTimestamp("EndDate"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading EndDate: " + sqe.getMessage());
    }

    try {
        onlineTool.setSubmitted(rs.getTimestamp("Submitted"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading SubmittedDate: " + sqe.getMessage());
    }

    try {
        onlineTool.setCompleted(rs.getTimestamp("Completed"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error reading CompletedDate: " + sqe.getMessage());
    }

    return onlineTool;
}

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

public TodoCommand(JDA api) {
    this.api = api;
    try {/*from   w w  w.ja  v  a2 s. com*/
        ResultSet sqlTodoLists = Database.getInstance().getStatement(GET_TODO_LISTS).executeQuery();
        while (sqlTodoLists.next()) {
            String label = sqlTodoLists.getString(2);
            TodoList todoList = new TodoList(sqlTodoLists.getInt(1), //Id
                    label, sqlTodoLists.getString(3), //OwnerId
                    sqlTodoLists.getBoolean(4) //Locked
            );
            todoLists.put(label, todoList);

            PreparedStatement getEntries = Database.getInstance().getStatement(GET_TODO_ENTRIES);
            getEntries.setInt(1, todoList.id);
            ResultSet sqlTodoEntries = getEntries.executeQuery();
            while (sqlTodoEntries.next()) {
                TodoEntry todoEntry = new TodoEntry(sqlTodoEntries.getInt(1), //Id
                        sqlTodoEntries.getString(2), //Content
                        sqlTodoEntries.getBoolean(3) //Checked
                );
                todoList.entries.add(todoEntry);
            }
            getEntries.clearParameters();

            PreparedStatement getUsers = Database.getInstance().getStatement(GET_TODO_USERS);
            getUsers.setInt(1, todoList.id);
            ResultSet sqlTodoUsers = getUsers.executeQuery();
            while (sqlTodoUsers.next()) {
                todoList.allowedUsers.add(sqlTodoUsers.getString(1)); //UserId
            }
            getUsers.clearParameters();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

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

/**
 * {@inheritDoc}/*from   w w w  .j  av a 2s.  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<ACLAssignment> loadAssignments(Long aclId, Long groupId) throws FxApplicationException {
    Connection con = null;
    Statement stmt = null;
    String curSql;
    UserTicket ticket = FxContext.getUserTicket();

    // Permission & Exists check
    checkPermissions(ticket, groupId, aclId, false);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // load assignments
        //                   1             2       3         4         5           6           7
        curSql = "SELECT ass.USERGROUP,ass.ACL,ass.PREAD,ass.PEDIT,ass.PREMOVE,ass.PEXPORT,ass.PREL," +
        //   8        ,      9        10             11             12              13
                "ass.PCREATE,acl.CAT_TYPE,ass.CREATED_BY,ass.CREATED_AT,ass.MODIFIED_BY,ass.MODIFIED_AT "
                + "FROM " + TBL_ACLS_ASSIGNMENT + " ass, " + TBL_ACLS + " acl WHERE " + "ass.ACL=acl.ID AND "
                + ((groupId != null) ? "USERGROUP=" + groupId : "")
                + ((groupId != null && aclId != null) ? " AND " : "") + ((aclId != null) ? "ACL=" + aclId : "");

        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);

        // Read the data
        ArrayList<ACLAssignment> result = new ArrayList<ACLAssignment>(20);
        while (rs != null && rs.next())
            result.add(new ACLAssignment(rs.getLong(2), rs.getLong(1), rs.getBoolean(3), rs.getBoolean(4),
                    rs.getBoolean(7), rs.getBoolean(5), rs.getBoolean(6), rs.getBoolean(8),
                    ACLCategory.getById(rs.getByte(9)), LifeCycleInfoImpl.load(rs, 10, 11, 12, 13)));

        // Return the found entries
        result.trimToSize();
        return result;
    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.aclAssignment.loadFailed");
    } finally {
        Database.closeObjects(ACLEngineBean.class, con, stmt);
    }
}

From source file:ru.org.linux.edithistory.EditHistoryDao.java

/**
 *     /?./*from ww w .j av a2  s.c  o  m*/
 *
 * @param id id 
 * @param objectTypeEnum :   
 * @return ??  
 */
public List<EditHistoryDto> getEditInfo(int id, EditHistoryObjectTypeEnum objectTypeEnum) {
    final List<EditHistoryDto> editInfoDTOs = new ArrayList<>();
    jdbcTemplate.query(queryEditInfo, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            EditHistoryDto editHistoryDto = new EditHistoryDto();
            editHistoryDto.setId(resultSet.getInt("id"));
            editHistoryDto.setMsgid(resultSet.getInt("msgid"));
            editHistoryDto.setEditor(resultSet.getInt("editor"));
            editHistoryDto.setOldmessage(resultSet.getString("oldmessage"));
            editHistoryDto.setEditdate(resultSet.getTimestamp("editdate"));
            editHistoryDto.setOldtitle(resultSet.getString("oldtitle"));
            editHistoryDto.setOldtags(resultSet.getString("oldtags"));
            editHistoryDto.setObjectType(resultSet.getString("object_type"));

            editHistoryDto.setOldimage(resultSet.getInt("oldimage"));
            if (resultSet.wasNull()) {
                editHistoryDto.setOldimage(null);
            }

            editHistoryDto.setOldminor(resultSet.getBoolean("oldminor"));
            if (resultSet.wasNull()) {
                editHistoryDto.setOldminor(null);
            }

            editInfoDTOs.add(editHistoryDto);
        }
    }, id, objectTypeEnum.toString());
    return editInfoDTOs;
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.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.
 *
 * <p>// w  w  w.jav  a  2s. c om
 * 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 Integer.valueOf(rs.getInt(index));

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

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

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

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

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

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

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

    } else if (propType.equals(SQLXML.class)) {
        return rs.getSQLXML(index);

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

}

From source file:com.oracle2hsqldb.dialect.Oracle9Dialect.java

/**
 * performance improvement over GenericDialect's getColumns()
 */// w w w  .j  a va2s .c o  m
public Iterator getColumns(final DataSource dataSource, String schemaName) throws SQLException {
    final List specs = new LinkedList();
    new JdbcTemplate(dataSource).query("SELECT " + "column_name, " + "table_name, " + "data_type, "
            + "NVL(data_precision, data_length) AS column_size," + "data_scale AS decimal_digits,"
            + "DECODE(nullable, 'Y', 1, 0) AS nullable," + "data_default AS column_def "
            + "FROM user_tab_columns", new RowCallbackHandler() {
                public void processRow(ResultSet columns) throws SQLException {
                    // retrieve values ahead of time, otherwise you get a stream
                    // closed error from Oracle
                    String columnName = columns.getString("COLUMN_NAME");
                    if (log.isDebugEnabled())
                        log.debug("Reading column " + columnName);
                    String tableName = columns.getString("TABLE_NAME");
                    try {
                        int dataType = getType(columns.getString("DATA_TYPE"));

                        int columnSize = columns.getInt("COLUMN_SIZE");
                        int decimalDigits = columns.getInt("DECIMAL_DIGITS");
                        boolean isNullable = columns.getBoolean("NULLABLE");
                        String columnDef = columns.getString("COLUMN_DEF");
                        specs.add(new Column.Spec(tableName, new Column(columnName, dataType, columnSize,
                                decimalDigits, isNullable, parseDefaultValue(columnDef, dataType))));
                    } catch (IllegalArgumentException e) {
                        log.error("Problems with column " + columnName + " from table name  " + tableName);
                        throw new SQLException(
                                "Problems with column " + columnName + " from table " + tableName, e);
                    }
                }
            });
    return specs.iterator();
}