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.chariotsolutions.crowd.connector.PrincipalRowMapper.java

public RemotePrincipal mapRow(ResultSet rs, int i) throws SQLException {

    long id = rs.getLong("id");
    String username = rs.getString("user_name");
    String email = rs.getString("email");
    String firstName = rs.getString("first_name");
    String lastName = rs.getString("last_name");
    String company = rs.getString("company");
    String title = rs.getString("title");
    String phone = rs.getString("phone");
    String country = rs.getString("country");

    String password = rs.getString("password");
    PasswordCredential credential = new PasswordCredential(password, true);

    boolean active = !rs.getBoolean("account_disabled");
    Date created = rs.getDate("created");

    RemotePrincipal principal = new RemotePrincipal();

    principal.setID(id);//from w w w  . j  a  va2 s  . c o m
    principal.setName(username);
    principal.setEmail(email);
    principal.setActive(active);
    principal.setAttribute(RemotePrincipal.FIRSTNAME, firstName);
    principal.setAttribute(RemotePrincipal.LASTNAME, lastName);
    principal.setAttribute(RemotePrincipal.DISPLAYNAME, firstName + " " + lastName);

    principal.setAttribute("company", company);
    principal.setAttribute("title", title);
    principal.setAttribute("phone", phone);
    principal.setAttribute("country", country);

    principal.setConception(created);

    principal.setCredentials(Collections.singletonList(credential));
    principal.setCredentialHistory(Collections.singletonList(credential));

    return principal;
}

From source file:net.algem.security.UserDaoImpl.java

@Override
public List<Email> getEmailsFromContact(final int id) {
    String query = "SELECT email,archive,idx FROM email WHERE idper = ?";
    return jdbcTemplate.query(query, new RowMapper<Email>() {
        @Override/*from w  ww.  j  av  a 2  s . c o m*/
        public Email mapRow(ResultSet rs, int i) throws SQLException {
            Email e = new Email();
            e.setIdper(id);
            e.setEmail(rs.getString(1));
            e.setArchive(rs.getBoolean(2));
            e.setIndex(rs.getShort(3));
            return e;
        }
    }, id);
}

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

public Iterator getColumns(final DataSource dataSource, final String schemaName) throws SQLException {
    final List result = new LinkedList();
    MetaDataJdbcTemplate template = new MetaDataJdbcTemplate(dataSource) {
        protected ResultSet getResults(DatabaseMetaData metaData) throws SQLException {
            return metaData.getColumns(null, schemaName, null, null);
        }/*from   w  ww. j  a va  2  s  . co m*/
    };
    template.query(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");
            int dataType = columns.getInt("DATA_TYPE");
            String tableName = columns.getString("TABLE_NAME");
            int columnSize = columns.getInt("COLUMN_SIZE");
            int decimalDigits = columns.getInt("DECIMAL_DIGITS");
            boolean isNullable = columns.getBoolean("NULLABLE");
            String columnDef = columns.getString("COLUMN_DEF");
            result.add(new Column.Spec(tableName, new Column(columnName, dataType, columnSize, decimalDigits,
                    isNullable, parseDefaultValue(columnDef, dataType))));
        }
    });
    return result.iterator();
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public Purchase getById(int id) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE purchase_id =?";
    return jdbcTemplate.queryForObject(sql, new Object[] { id }, new RowMapper<Purchase>() {

        @Override/*from w  ww  .j a  va 2s. c  om*/
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:com.leapfrog.inventorymanagementsystem.dao.impl.PurchaseDAOImpl.java

@Override
public List<Purchase> getALL(boolean status) throws SQLException, ClassNotFoundException {
    String sql = "SELECT * FROM tbl_purchase WHERE 1=1";

    if (status) {
        sql += " AND status=1 ";
    }//from  ww w.j  a  v  a  2  s.com
    return jdbcTemplate.query(sql, new RowMapper<Purchase>() {

        @Override
        public Purchase mapRow(ResultSet rs, int i) throws SQLException {
            Purchase p = new Purchase();
            p.setId(rs.getInt("purchase_id"));
            p.setProductName(rs.getString("product_name"));
            p.setCostPrice(rs.getInt("cost_price"));
            p.setDiscount(rs.getBigDecimal("discount"));
            p.setQuantity(rs.getInt("quantity"));
            p.setTotalCost(rs.getInt("total_cost"));
            p.setSupplierId(rs.getInt("supplier_id"));
            p.setPurchaseDate(rs.getDate("purchase_date"));
            p.setPaymentMethod(rs.getString("payment_method"));
            p.setStatus(rs.getBoolean("status"));

            return p;
        }
    });
}

From source file:com.p000ison.dev.simpleclans2.converter.Converter.java

public void convertClans() throws SQLException {
    ResultSet result = from.query("SELECT * FROM `sc_clans`;");

    while (result.next()) {
        JSONObject flags = new JSONObject();

        String name = result.getString("name");
        String tag = result.getString("tag");
        boolean verified = result.getBoolean("verified");
        boolean friendly_fire = result.getBoolean("friendly_fire");
        long founded = result.getLong("founded");
        long last_used = result.getLong("last_used");
        String flagsString = result.getString("flags");
        String cape = result.getString("cape_url");

        ConvertedClan clan = new ConvertedClan(tag);
        clan.setPackedAllies(result.getString("packed_allies"));
        clan.serPackedRivals(result.getString("packed_rivals"));

        if (friendly_fire) {
            flags.put("ff", friendly_fire);
        }/*  ww  w  .  j  a  v a  2 s  . co m*/

        if (cape != null && !cape.isEmpty()) {
            flags.put("cape-url", cape);
        }

        JSONParser parser = new JSONParser();
        try {
            JSONObject object = (JSONObject) parser.parse(flagsString);
            String world = object.get("homeWorld").toString();
            if (!world.isEmpty()) {
                int x = ((Long) object.get("homeX")).intValue();
                int y = ((Long) object.get("homeY")).intValue();
                int z = ((Long) object.get("homeZ")).intValue();

                flags.put("home", x + ":" + y + ":" + z + ":" + world + ":0:0");
            }

            clan.setRawWarring((JSONArray) object.get("warring"));
        } catch (ParseException e) {
            Logging.debug(e, true);
            continue;
        }

        insertClan(name, tag, verified, founded, last_used, flags.isEmpty() ? null : flags.toJSONString(),
                result.getDouble("balance"));

        String selectLastQuery = "SELECT `id` FROM `sc2_clans` ORDER BY ID DESC LIMIT 1;";

        ResultSet selectLast = to.query(selectLastQuery);
        selectLast.next();
        clan.setId(selectLast.getLong("id"));
        selectLast.close();

        insertBB(Arrays.asList(result.getString("packed_bb").split("\\s*(\\||$)")), clan.getId());

        clans.add(clan);
    }

    for (ConvertedClan clan : clans) {
        JSONArray allies = new JSONArray();
        JSONArray rivals = new JSONArray();
        JSONArray warring = new JSONArray();

        for (String allyTag : clan.getRawAllies()) {
            long allyID = getIDByTag(allyTag);
            if (allyID != -1) {
                allies.add(allyID);
            }
        }

        for (String rivalTag : clan.getRawAllies()) {
            long rivalID = getIDByTag(rivalTag);
            if (rivalID != -1) {
                rivals.add(rivalID);
            }
        }

        for (String warringTag : clan.getRawWarring()) {
            long warringID = getIDByTag(warringTag);
            if (warringID != -1) {
                warring.add(warringID);
            }
        }

        if (!allies.isEmpty()) {
            updateClan.setString(1, allies.toJSONString());
        } else {
            updateClan.setNull(1, Types.VARCHAR);
        }

        if (!rivals.isEmpty()) {
            updateClan.setString(2, rivals.toJSONString());
        } else {
            updateClan.setNull(2, Types.VARCHAR);
        }

        if (!warring.isEmpty()) {
            updateClan.setString(3, warring.toJSONString());
        } else {
            updateClan.setNull(3, Types.VARCHAR);
        }

        updateClan.setLong(4, clan.getId());
        updateClan.executeUpdate();
    }
}

From source file:com.wso2telco.gsma.authenticators.DBUtils.java

/**
 * Get MSISDN properties by operator Id.
 *
 * @param operatorId   operator Id.//from   w  ww . j av  a  2s .  co m
 * @param operatorName operator Name.
 * @return MSISDN properties of given operator.
 * @throws SQLException
 * @throws NamingException
 */
@Deprecated
private static List<MSISDNHeader> getMSISDNPropertiesByOperatorId(int operatorId, String operatorName,
        Connection connection) throws SQLException, AuthenticatorException {
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    List<MSISDNHeader> msisdnHeaderList = new ArrayList<MSISDNHeader>();
    String queryToGetOperatorProperty = "SELECT  msisdnHeaderName, isHeaderEncrypted, encryptionImplementation, "
            + "msisdnEncryptionKey, priority FROM operators_msisdn_headers_properties WHERE operatorId = ? ORDER BY"
            + " priority ASC";
    try {
        preparedStatement = connection.prepareStatement(queryToGetOperatorProperty);
        preparedStatement.setInt(1, operatorId);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            MSISDNHeader msisdnHeader = new MSISDNHeader();
            msisdnHeader.setMsisdnHeaderName(resultSet.getString("msisdnHeaderName"));
            msisdnHeader.setHeaderEncrypted(resultSet.getBoolean("isHeaderEncrypted"));
            msisdnHeader.setHeaderEncryptionMethod(resultSet.getString("encryptionImplementation"));
            msisdnHeader.setHeaderEncryptionKey(resultSet.getString("msisdnEncryptionKey"));
            msisdnHeader.setPriority(resultSet.getInt("priority"));
            msisdnHeaderList.add(msisdnHeader);
        }
    } catch (SQLException e) {
        log.error("Error occurred while retrieving operator MSISDN properties of operator : " + operatorName,
                e);
        throw e;
    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, resultSet, preparedStatement);
    }
    return msisdnHeaderList;
}

From source file:net.sf.l2j.gameserver.datatables.NpcWalkerRoutesTable.java

public void load() {
    _routes = new FastList<L2NpcWalkerNode>();
    java.sql.Connection con = null;
    try {/*w  w  w  .jav  a 2 s  . co  m*/
        con = L2DatabaseFactory.getInstance().getConnection();
        PreparedStatement statement = con.prepareStatement(
                "SELECT route_id, npc_id, move_point, chatText, move_x, move_y, move_z, delay, running FROM walker_routes");
        ResultSet rset = statement.executeQuery();
        L2NpcWalkerNode route;
        while (rset.next()) {
            route = new L2NpcWalkerNode();
            route.setRouteId(rset.getInt("route_id"));
            route.setNpcId(rset.getInt("npc_id"));
            route.setMovePoint(rset.getString("move_point"));
            route.setChatText(rset.getString("chatText"));
            route.setMoveX(rset.getInt("move_x"));
            route.setMoveY(rset.getInt("move_y"));
            route.setMoveZ(rset.getInt("move_z"));
            route.setDelay(rset.getInt("delay"));
            route.setRunning(rset.getBoolean("running"));
            _routes.add(route);
        }
        rset.close();
        statement.close();
        _log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
        rset.close();
        statement.close();
    } catch (Exception e) {
        _log.fatal("WalkerRoutesTable: Error while loading Npc Walkers Routes: " + e.getMessage());
    } finally {
        try {
            con.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.bt.aloha.batchtest.PerformanceMeasurmentDao.java

@SuppressWarnings("unchecked")
public List<Metrics> findMetricsByRunId(long runId) {

    if (!exists) {
        log.warn("record skipped as schema does not exists");
        return null;
    }//from  w  ww .j a  va2  s . com
    List<Metrics> metrics = null;
    try {
        metrics = jdbcTemplate.query("select unitPerSecond, averageDuration,"
                + "numberOfRuns, numberOfSuccessfulRuns, variance, standardDeviation, success, description, threadInfo, testType "
                + "from Performance where runId=?", new Object[] { runId }, new RowMapper() {
                    public Object mapRow(ResultSet rs, int row) throws SQLException {
                        double ups = rs.getDouble("unitPerSecond");
                        double ad = rs.getDouble("averageDuration");
                        long nor = rs.getLong("numberOfRuns");
                        long nosr = rs.getLong("numberOfSuccessfulRuns");
                        double v = rs.getDouble("variance");
                        double sd = rs.getDouble("standardDeviation");
                        boolean s = rs.getBoolean("success");
                        String d = rs.getString("description");
                        String ti = rs.getString("threadInfo");
                        String tt = rs.getString("testType");
                        Metrics m = new Metrics(tt, ups, ad, nor, nosr, v, sd, s, d);
                        m.setThreadInfo(ti);
                        return m;
                    }
                });
    } catch (DataAccessException e) {
        log.error("Unable to access data for runId: " + runId, e);
    }
    return metrics;
}

From source file:com.l2jfree.gameserver.datatables.NpcWalkerRoutesTable.java

public void load() {
    _routes.clear();//from  www . j  a va  2s.  c  o m
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "SELECT route_id, npc_id, move_point, chatText, move_x, move_y, move_z, delay, running FROM walker_routes ORDER By move_point ASC");
        ResultSet rset = statement.executeQuery();
        L2NpcWalkerNode route;
        while (rset.next()) {
            route = new L2NpcWalkerNode();
            route.setRouteId(rset.getInt("route_id"));
            route.setNpcId(rset.getInt("npc_id"));
            route.setMovePoint(rset.getString("move_point"));
            route.setChatText(rset.getString("chatText"));

            route.setMoveX(rset.getInt("move_x"));
            route.setMoveY(rset.getInt("move_y"));
            route.setMoveZ(rset.getInt("move_z"));
            route.setDelay(rset.getInt("delay"));
            route.setRunning(rset.getBoolean("running"));

            _routes.add(route);
        }

        rset.close();
        statement.close();

        _log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
    } catch (Exception e) {
        _log.fatal("WalkerRoutesTable: Error while loading Npc Walker Routes: " + e.getMessage(), e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}