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:ru.org.linux.spring.dao.MsgbaseDao.java

public MessageText getMessageText(int msgid) {
    return jdbcTemplate.queryForObject(QUERY_MESSAGE_TEXT, new RowMapper<MessageText>() {
        @Override//www  .j  a  v  a 2s . com
        public MessageText mapRow(ResultSet resultSet, int i) throws SQLException {
            String text = resultSet.getString("message");
            boolean lorcode = resultSet.getBoolean("bbcode");

            return new MessageText(text, lorcode);
        }
    }, msgid);
}

From source file:ece356.UserDBAO.java

public static FriendShipStatus addFriend(String friendA, String friendB)
        throws ClassNotFoundException, SQLException, NamingException {
    Connection con = null;/*from   w w  w.j a  v  a  2s  . c  om*/
    PreparedStatement pstmt = null;
    try {
        con = getConnection();
        // First check if sender has already sent a request to receiver in the past
        // If he has, then check if it's accepted
        // If it is accepted, then return ALREADY_FRIENDS
        // If it is not accepted, then return WAITING_FOR_ACCEPT
        // If he hasn't then check if the receiver has sent a request to sender in the past
        // If he hasn't, then make an INSERT and return REQUEST_SENT
        // If he has, then check if it's accepted
        // If it's not accepted, then UPDATE and make isAccepted = true and return FRIENDSHIP_ESTABLISHED                            
        // If it is accepted, then return ALREADY_FRIENDS                        

        // Find if this request is already there
        String query = "SELECT * FROM friend where sent_username = ? AND recieved_username = ?";
        pstmt = con.prepareStatement(query);
        pstmt.setString(1, friendA);
        pstmt.setString(2, friendB);

        ResultSet resultSet;
        resultSet = pstmt.executeQuery();
        resultSet.next();

        if (resultSet.first()) {
            System.out.println("RESULT SET: " + resultSet.getString("sent_username") + " "
                    + resultSet.getString("recieved_username"));
            boolean isAccepted = resultSet.getBoolean("isAccepted");
            if (isAccepted) {
                return FriendShipStatus.ALREADY_FRIENDS;
            } else {
                return FriendShipStatus.WAITING_FOR_ACCEPT;
            }
        } else {
            pstmt = con.prepareStatement(query);
            pstmt.setString(1, friendB);
            pstmt.setString(2, friendA);
            resultSet = pstmt.executeQuery();
            resultSet.next();
            if (resultSet.first()) {
                System.out.println("RESULT SET: " + resultSet.getString("sent_username") + " "
                        + resultSet.getString("recieved_username"));
                boolean isAccepted = resultSet.getBoolean("isAccepted");
                if (isAccepted) {
                    return FriendShipStatus.ALREADY_FRIENDS;
                } else {
                    String update = "UPDATE friend SET isAccepted = ? where sent_username = ? AND recieved_username = ?;";
                    pstmt = con.prepareStatement(update);
                    pstmt.setBoolean(1, true);
                    pstmt.setString(2, friendB);
                    pstmt.setString(3, friendA);
                    pstmt.executeUpdate();
                    return FriendShipStatus.FRIENDSHIP_ESTABLISHED;
                }
            } else {
                pstmt = con.prepareStatement(
                        "INSERT INTO friend (sent_username, recieved_username) VALUES (?, ?);");
                pstmt.setString(1, friendA);
                pstmt.setString(2, friendB);
                pstmt.executeUpdate();
                return FriendShipStatus.REQUEST_SENT;
            }
        }
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
}

From source file:com.phideltcmu.recruiter.server.dao.mapper.InternalUserSetExtractor.java

@Override
public Object extractData(ResultSet resultSet) throws SQLException, DataAccessException {
    InternalUser user = new InternalUser();
    user.setDatabaseID(resultSet.getInt(1));
    user.setName(resultSet.getString(2));
    user.setAdmin(resultSet.getBoolean(3));
    return user;//from  w ww . j a  v a2  s.  com
}

From source file:com.surveypanel.dao.FormRowHandler.java

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    FormDTO formDTO = new FormDTO();
    formDTO.setId(rs.getString("id"));
    formDTO.setSurveyId(rs.getLong("surveyId"));
    formDTO.setQualified(rs.getBoolean("qualified"));
    formDTO.setFinish(rs.getBoolean("finish"));
    formDTO.setUpdated(rs.getDate("updated"));
    formDTO.setCreated(rs.getDate("created"));
    formDTO.setVariables(StateRowMapper.getMap(rs.getBlob("js_data")));
    formDTO.setXmlContent(rs.getString("xml_data"));
    return formDTO;
}

From source file:eionet.transfer.dao.UserManagementServiceJdbc.java

@Override
public List<UserDetails> getAllUsers() {
    return getJdbcTemplate().query(DEF_GET_ALL_USERS_SQL, new String[] {}, new RowMapper<UserDetails>() {
        public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException {
            String username = rs.getString(1);
            String password = rs.getString(2);
            boolean enabled = rs.getBoolean(3);
            return new User(username, password, enabled, true, true, true, loadUserAuthorities(username));
        }//from  www  .ja  va  2  s .c o m

    });
}

From source file:ru.org.linux.spring.dao.MsgbaseDao.java

public Map<Integer, MessageText> getMessageText(Collection<Integer> msgids) {
    if (msgids.isEmpty()) {
        return ImmutableMap.of();
    }//w  w w .j  a  va2s  . com

    final Map<Integer, MessageText> out = Maps.newHashMapWithExpectedSize(msgids.size());

    namedJdbcTemplate.query("SELECT message, bbcode, id FROM msgbase WHERE id IN (:list)",
            ImmutableMap.of("list", msgids), new RowCallbackHandler() {
                @Override
                public void processRow(ResultSet resultSet) throws SQLException {
                    String text = resultSet.getString("message");
                    boolean lorcode = resultSet.getBoolean("bbcode");

                    out.put(resultSet.getInt("id"), new MessageText(text, lorcode));
                }
            });

    return out;
}

From source file:net.navasoft.madcoin.backend.services.security.ProviderEmailMapper.java

/**
 * Map row./*  w  w w .  j  av a 2s  . c  o  m*/
 * 
 * @param rs
 *            the rs
 * @param arg1
 *            the arg1
 * @return the user
 * @throws SQLException
 *             the SQL exception
 * @since 17/08/2014, 06:20:43 PM
 */
@Override
public User mapRow(ResultSet rs, int arg1) throws SQLException {
    String mail = rs.getString(USER_COLUMN);
    return new User(mail, rs.getString(PASSWORD_COLUMN), rs.getBoolean(ENABLED_COLUMN), true, true, true,
            getAuthorities(mail));
}

From source file:com.nabla.dc.server.xml.settings.XmlCompany.java

public XmlCompany(final ResultSet rs) throws SQLException {
    name = rs.getString(2);/*from   w w w  .  j  a va 2 s .  co m*/
    active = rs.getBoolean(3);
    load(rs.getStatement().getConnection(), rs.getInt(1));
}

From source file:com.vertica.hivestoragehandler.VerticaRecordWriter.java

public VerticaRecordWriter(Connection conn, String writerTable, long batch) throws SQLException {
    this.connection = conn;
    batchSize = batch;/* w w w .  j av a2 s . c  om*/

    vTable = new VerticaRelation(writerTable);

    StringBuilder sb = new StringBuilder();
    sb.append("INSERT INTO ");
    sb.append(vTable.getQualifiedName());

    StringBuilder values = new StringBuilder();
    values.append(" VALUES(");
    sb.append("(");

    String metaStmt = "select ordinal_position, column_name, data_type, is_identity, data_type_name "
            + "from v_catalog.odbc_columns " + "where schema_name = ? and table_name = ? "
            + "order by ordinal_position;";

    PreparedStatement stmt = conn.prepareStatement(metaStmt);
    stmt.setString(1, vTable.getSchema());
    stmt.setString(2, vTable.getTable());

    ResultSet rs = stmt.executeQuery();
    boolean addComma = false;
    while (rs.next()) {
        if (!rs.getBoolean(4)) {
            if (addComma) {
                sb.append(',');
                values.append(',');
            }
            sb.append(rs.getString(2));
            values.append('?');
            addComma = true;
        } else {
            LOG.debug("Skipping identity column " + rs.getString(4));
        }
    }

    sb.append(')');
    values.append(')');
    sb.append(values.toString());

    statement = conn.prepareStatement(sb.toString());
}

From source file:com.l2jserver.model.template.NPCTemplateConverter.java

private static Object[] fillNPC(ResultSet rs) throws SQLException, IOException {
    final ObjectFactory factory = new ObjectFactory();

    final NPCTemplate template = factory.createNPCTemplate();
    template.setID(new NPCTemplateID(rs.getInt("idTemplate"), null));

    template.setController(controllers.get(rs.getString("type")));
    if (template.getController() == null)
        template.setController(NotImplementedNPCController.class);
    template.setInfo(factory.createNPCTemplateInfo());

    template.getInfo().setName(factory.createNPCTemplateInfoName());
    template.getInfo().getName().setValue(rs.getString("name"));
    // template.getInfo().getName().setDisplay(rs.getBoolean("show_name"));
    template.getInfo().getName().setSend(rs.getBoolean("serverSideName"));

    template.getInfo().setTitle(factory.createNPCTemplateInfoTitle());
    template.getInfo().getTitle().setValue(rs.getString("title"));
    template.getInfo().getTitle().setSend(rs.getBoolean("serverSideTitle"));

    if (template.getInfo().getName().getValue().length() == 0)
        template.getInfo().setName(null);
    if (template.getInfo().getTitle().getValue().length() == 0)
        template.getInfo().setTitle(null);

    template.getInfo().setLevel(rs.getInt("level"));
    template.getInfo().setRace(getRace(rs.getInt("race")));
    if (!rs.getString("sex").equals("etc"))
        template.getInfo().setSex(ActorSex.valueOf(rs.getString("sex").toUpperCase()));
    // template.info.attackable = rs.getBoolean("attackable");
    // template.getInfo().setTargetable(rs.getBoolean("targetable"));
    template.getInfo().setTargetable(true);
    // template.getInfo().setAggressive(rs.getBoolean("aggro"));
    template.getInfo().setAggressive(true);
    template.getInfo().setAttackable(true); // FIXME

    template.getInfo().setStats(factory.createNPCTemplateInfoStats());

    template.getInfo().getStats().setHp(factory.createNPCTemplateInfoStatsHp());
    template.getInfo().getStats().getHp().setMax(rs.getDouble("hp"));
    template.getInfo().getStats().getHp().setRegen(rs.getDouble("hpreg"));

    template.getInfo().getStats().setMp(factory.createNPCTemplateInfoStatsMp());
    template.getInfo().getStats().getMp().setMax(rs.getDouble("mp"));
    template.getInfo().getStats().getMp().setRegen(rs.getDouble("mpreg"));

    template.getInfo().getStats().setAttack(factory.createNPCTemplateInfoStatsAttack());
    template.getInfo().getStats().getAttack().setRange(rs.getInt("attackrange"));
    template.getInfo().getStats().getAttack().setCritical(rs.getInt("critical"));

    template.getInfo().getStats().getAttack().setPhysical(factory.createNPCTemplateInfoStatsAttackPhysical());
    template.getInfo().getStats().getAttack().getPhysical().setDamage(rs.getDouble("patk"));
    template.getInfo().getStats().getAttack().getPhysical().setSpeed(rs.getDouble("atkspd"));

    template.getInfo().getStats().getAttack().setMagical(factory.createNPCTemplateInfoStatsAttackMagical());
    template.getInfo().getStats().getAttack().getMagical().setDamage(rs.getDouble("matk"));
    template.getInfo().getStats().getAttack().getMagical().setSpeed(rs.getDouble("matkspd"));

    template.getInfo().getStats().setDefense(factory.createNPCTemplateInfoStatsDefense());
    template.getInfo().getStats().getDefense().setPhysical(factory.createNPCTemplateInfoStatsDefensePhysical());
    template.getInfo().getStats().getDefense().getPhysical().setValue(rs.getDouble("pdef"));
    template.getInfo().getStats().getDefense().setMagical(factory.createNPCTemplateInfoStatsDefenseMagical());
    template.getInfo().getStats().getDefense().getMagical().setValue(rs.getDouble("mdef"));

    template.getInfo().getStats().setMove(factory.createNPCTemplateInfoStatsMove());
    template.getInfo().getStats().getMove().setRun(rs.getDouble("runspd"));
    template.getInfo().getStats().getMove().setWalk(rs.getDouble("walkspd"));

    template.getInfo().getStats().setBase(factory.createNPCTemplateInfoStatsBase());
    template.getInfo().getStats().getBase().setInt(rs.getInt("int"));
    template.getInfo().getStats().getBase().setStr(rs.getInt("str"));
    template.getInfo().getStats().getBase().setCon(rs.getInt("con"));
    template.getInfo().getStats().getBase().setDex(rs.getInt("dex"));
    template.getInfo().getStats().getBase().setWit(rs.getInt("wit"));
    template.getInfo().getStats().getBase().setMen(rs.getInt("men"));

    template.getInfo().setExperience(rs.getLong("exp"));
    template.getInfo().setSp(rs.getInt("sp"));

    if (rs.getInt("rhand") > 0 || rs.getInt("lhand") > 0)
        template.getInfo().setItem(factory.createNPCTemplateInfoItem());
    if (rs.getInt("rhand") > 0)
        template.getInfo().getItem().setRightHand(new ItemTemplateID(rs.getInt("rhand"), null));
    if (rs.getInt("lhand") > 0)
        template.getInfo().getItem().setLeftHand(new ItemTemplateID(rs.getInt("lhand"), null));

    template.getInfo().setCollision(factory.createNPCTemplateInfoCollision());
    template.getInfo().getCollision().setRadius(rs.getDouble("collision_radius"));
    template.getInfo().getCollision().setHeigth(rs.getDouble("collision_height"));

    template.setDroplist(fillDropList(factory, rs, template.getID().getID()));
    template.setSkills(fillSkillList(factory, rs, template.getID().getID()));
    template.setTalk(fillHtmlChat(factory, template.getID().getID()));

    return new Object[] { template, createParentType(rs.getString("type")) };
}