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.alfaariss.oa.authentication.remote.aselect.idp.storage.jdbc.IDPJDBCStorage.java

/**
 * @see com.alfaariss.oa.engine.core.idp.storage.IIDPStorage#getIDP(java.lang.String)
 *///  www  .j  a v a  2 s. com
public IIDP getIDP(String id) throws OAException {
    Connection connection = null;
    PreparedStatement pSelect = null;
    ResultSet resultSet = null;
    ASelectIDP oASelectIDP = null;
    try {
        connection = _dataSource.getConnection();

        pSelect = connection.prepareStatement(_querySelect);
        pSelect.setBoolean(1, true);
        pSelect.setString(2, id);
        resultSet = pSelect.executeQuery();
        if (resultSet.next()) {
            oASelectIDP = 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));
        }
    } catch (Exception e) {
        _logger.fatal("Internal error during retrieval of IDP with id: " + id, 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 oASelectIDP;
}

From source file:com.liferay.portal.upgrade.util.Table.java

public Object getValue(ResultSet rs, String name, Integer type) throws Exception {

    Object value = null;/*  w  w  w  .j ava 2s .c o  m*/

    int t = type.intValue();

    if (t == Types.BIGINT) {
        try {
            value = GetterUtil.getLong(rs.getLong(name));
        } catch (SQLException e) {
            value = GetterUtil.getLong(rs.getString(name));
        }
    } else if (t == Types.BOOLEAN) {
        value = GetterUtil.getBoolean(rs.getBoolean(name));
    } else if (t == Types.CLOB) {
        try {
            Clob clob = rs.getClob(name);

            if (clob == null) {
                value = StringPool.BLANK;
            } else {
                UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(clob.getCharacterStream());

                StringBundler sb = new StringBundler();

                String line = null;

                while ((line = unsyncBufferedReader.readLine()) != null) {
                    if (sb.length() != 0) {
                        sb.append(SAFE_NEWLINE_CHARACTER);
                    }

                    sb.append(line);
                }

                value = sb.toString();
            }
        } catch (Exception e) {

            // If the database doesn't allow CLOB types for the column
            // value, then try retrieving it as a String

            value = GetterUtil.getString(rs.getString(name));
        }
    } else if (t == Types.DOUBLE) {
        value = GetterUtil.getDouble(rs.getDouble(name));
    } else if (t == Types.FLOAT) {
        value = GetterUtil.getFloat(rs.getFloat(name));
    } else if (t == Types.INTEGER) {
        value = GetterUtil.getInteger(rs.getInt(name));
    } else if (t == Types.SMALLINT) {
        value = GetterUtil.getShort(rs.getShort(name));
    } else if (t == Types.TIMESTAMP) {
        try {
            value = rs.getTimestamp(name);
        } catch (Exception e) {
        }

        if (value == null) {
            value = StringPool.NULL;
        }
    } else if (t == Types.VARCHAR) {
        value = GetterUtil.getString(rs.getString(name));
    } else {
        throw new UpgradeException("Upgrade code using unsupported class type " + type);
    }

    return value;
}

From source file:com.nabla.wapp.server.basic.general.ExportService.java

private boolean exportFile(final String id, final UserSession userSession, final HttpServletResponse response)
        throws IOException, SQLException, InternalErrorException {
    final Connection conn = db.getConnection();
    try {/*from  w ww.  ja  v a 2s .co  m*/
        final PreparedStatement stmt = StatementFormat.prepare(conn, "SELECT * FROM export WHERE id=?;", id);
        try {
            final ResultSet rs = stmt.executeQuery();
            try {
                if (!rs.next()) {
                    if (log.isDebugEnabled())
                        log.debug("failed to find file ID= " + id);
                    return false;
                }
                if (!userSession.getSessionId().equals(rs.getString("userSessionId"))) {
                    if (log.isTraceEnabled())
                        log.trace("invalid user session ID");
                    return false;
                }
                if (log.isTraceEnabled())
                    log.trace("exporting file " + id);
                response.reset();
                response.setBufferSize(DEFAULT_BUFFER_SIZE);
                response.setContentType(rs.getString("content_type"));
                if (rs.getBoolean("output_as_file")) {
                    // IMPORTANT:
                    // MUST be done before calling getOutputStream() otherwise no SaveAs dialogbox
                    response.setHeader("Content-Disposition",
                            MessageFormat.format("attachment; filename=\"{0}\"", rs.getString("name")));
                }
                IOUtils.copy(rs.getBinaryStream("content"), response.getOutputStream());
                /*   final BufferedInputStream input = new BufferedInputStream(rs.getBinaryStream("content"), DEFAULT_BUFFER_SIZE);
                   try {
                      final BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
                      try {
                         final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                         int length;
                         while ((length = input.read(buffer)) > 0)
                output.write(buffer, 0, length);
                      } finally {
                         output.close();
                      }
                   } finally {
                      input.close();
                   }*/
            } finally {
                rs.close();
                try {
                    Database.executeUpdate(conn, "DELETE FROM export WHERE id=?;", id);
                } catch (final SQLException e) {
                    if (log.isErrorEnabled())
                        log.error("failed to delete export record: " + e.getErrorCode() + "-" + e.getSQLState(),
                                e);
                }
            }
        } finally {
            stmt.close();
        }
    } finally {
        // remove any orphan export records i.e. older than 48h (beware of timezone!)
        final Calendar dt = Util.dateToCalendar(new Date());
        dt.add(GregorianCalendar.DATE, -2);
        try {
            Database.executeUpdate(conn, "DELETE FROM export WHERE created < ?;", Util.calendarToSqlDate(dt));
        } catch (final SQLException __) {
        }
        conn.close();
    }
    return true;
}

From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java

@Override
public List<SchemaSet> getSchemaSets(List<Integer> ids) {
    String sql = "SELECT * FROM T_SCHEMA_SET WHERE SCHEMA_SET_ID IN (:ids)";
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ids", ids);

    List<SchemaSet> items = getNamedParameterJdbcTemplate().query(sql, parameters, new RowMapper<SchemaSet>() {
        @Override//from w w  w .  j a v a  2 s.c o  m
        public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException {
            SchemaSet ss = new SchemaSet();
            ss.setId(rs.getInt("SCHEMA_SET_ID"));
            ss.setIdentifier(rs.getString("IDENTIFIER"));
            ss.setContinuityId(rs.getString("CONTINUITY_ID"));
            ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS")));
            ss.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
            ss.setWorkingUser(rs.getString("WORKING_USER"));
            ss.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
            ss.setUserModified(rs.getString("USER_MODIFIED"));
            ss.setComment(rs.getString("COMMENT"));
            ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
            ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED"));
            return ss;
        }
    });

    return items;
}

From source file:com.concursive.connect.web.modules.productcatalog.dao.Product.java

/**
 * Description of the Method/*from  www. j  a  v a2s.  c o m*/
 *
 * @param rs Description of the Parameter
 * @throws SQLException Description of the Exception
 */
public void buildRecord(ResultSet rs) throws SQLException {
    id = rs.getInt("product_id");
    name = rs.getString("product_name");
    priceDescription = rs.getString("price_description");
    details = rs.getString("details");
    basePrice = rs.getDouble("base_price");
    smallImage = rs.getString("small_image");
    largeImage = rs.getString("large_image");
    enabled = rs.getBoolean("enabled");
    contactInformationRequired = rs.getBoolean("contact_information_required");
    billingAddressRequired = rs.getBoolean("billing_address_required");
    shippingAddressRequired = rs.getBoolean("shipping_address_required");
    paymentRequired = rs.getBoolean("payment_required");
    orderDescription = rs.getString("order_description");
    sku = rs.getString("product_sku");
    showInCatalog = rs.getBoolean("show_in_catalog");
    cartEnabled = rs.getBoolean("cart_enabled");
    actionText = rs.getString("action_text");
}

From source file:mom.trd.opentheso.bdd.helper.GpsHelper.java

public GpsPreferences getGpsPreferences(HikariDataSource ds, String id_theso, int iduser, int id_source) {
    GpsPreferences gpsPreferences = new GpsPreferences();
    Connection conn;//from  w ww. j  a  va 2 s . co m
    Statement stmt;
    ResultSet resultSet;

    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select * from gps_preferences" + " where id_thesaurus = '" + id_theso
                        + "' and id_user =" + iduser + " and id_alignement_source =" + id_source;
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    gpsPreferences
                            .setGps_alignementautomatique(resultSet.getBoolean("gps_alignementautomatique"));
                    gpsPreferences.setGps_integrertraduction(resultSet.getBoolean("gps_integrertraduction"));
                    gpsPreferences
                            .setGps_reemplacertraduction(resultSet.getBoolean("gps_reemplacertraduction"));
                    gpsPreferences.setId_user(resultSet.getInt("id_user"));
                    gpsPreferences.setId_alignement_source(resultSet.getInt("id_alignement_source"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while Add coordonnes : ", sqle);
    }
    return gpsPreferences;
}

From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java

public static RowMapperFactory getScalarMapper(final Type itemType, final int idx, boolean req) {
    if (itemType == String.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getString(idx);
            }//ww w.  jav  a  2s  . c  o  m
        };
    }
    if (itemType == Integer.class || itemType == Integer.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getInt(idx);
            }
        };
    }
    if (itemType == URL.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getURL(idx);
            }
        };
    }
    if (itemType == BigInteger.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                final BigDecimal res = rs.getBigDecimal(idx);
                return res == null ? null : res.toBigInteger();
            }
        };
    }
    if (itemType == BigDecimal.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBigDecimal(idx);
            }
        };
    }
    if (itemType == InputStream.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBinaryStream(idx);
            }
        };
    }
    if (itemType == Boolean.class || itemType == Boolean.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBoolean(idx);
            }
        };
    }
    if (itemType == Blob.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBlob(idx);
            }
        };
    }
    if (itemType == java.sql.Date.class || itemType == java.util.Date.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getTimestamp(idx);
            }
        };
    }
    if (itemType instanceof Class) {
        final Class itemClass = (Class) itemType;
        final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass);
        if (columnMapper != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    return columnMapper.map(rs, idx);
                }
            };
        }
        final Converter converter = ConvertUtils.lookup(itemClass);
        if (converter != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(idx);
                    if (s == null) {
                        return null;
                    }
                    return converter.convert(itemClass, s);
                }
            };
        }
        if (Enum.class.isAssignableFrom((Class<?>) itemType)) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(idx);
                    if (s == null) {
                        return null;
                    }
                    //noinspection unchecked
                    return Enum.valueOf((Class<Enum>) itemType, s);
                }
            };
        }
    }
    if (req) {
        throw new IllegalArgumentException("no mapping defined for " + itemType);
    }
    return null;
}

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

/**
 * Load the MemoBean./*from  ww  w.  j a v a 2 s .c o  m*/
 *
 * @param rs the rs
 * @param fullResults the full results
 * @return the memo bean
 * @throws SQLException the sQL exception
 */
private MemoBean loadMemo(final ResultSet rs, final boolean fullResults) throws SQLException {

    final MemoBean memo = new MemoBean();

    memo.setId(rs.getInt("MemoId"));
    memo.setGUID(rs.getInt("GUID"));
    memo.setReferenceGUID(rs.getInt("ReferenceGUID"));
    memo.setType(rs.getString("Type"));
    memo.setObjectType(rs.getString("ObjectType"));
    memo.setSecurity(rs.getString("Security"));
    memo.setPriority(rs.getInt("Priority"));
    if (fullResults) {
        memo.setMessage(rs.getString("Message"));
    }
    try {
        memo.setExpires(rs.getDate("Expires"));
    } catch (SQLException sqe) {
        dataLogger.debug("Error loading Expires: " + sqe.getMessage());
    }

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

    if (fullResults) {
        /* Set the user details objects */
        UserBean user = new UserBean();
        user.setDN(rs.getString("CreatedBy"));
        user.setPreferredName(rs.getString("CreatedFirstName"));
        user.setLastName(rs.getString("CreatedLastName"));
        memo.setCreatedUser(user);

        UserBean modified = new UserBean();
        modified.setDN(rs.getString("ModifiedBy"));
        modified.setPreferredName(rs.getString("ModifiedFirstName"));
        modified.setLastName(rs.getString("ModifiedLastName"));
        memo.setModifiedUser(modified);
    }

    return memo;
}

From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java

public static RowMapperFactory getScalarRowMapperFactory(final Type itemType, final String name, boolean req) {
    if (itemType == String.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getString(name);
            }/*from  w  ww.j a  v a 2  s  .  co m*/
        };
    }
    if (itemType == Integer.class || itemType == Integer.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getInt(name);
            }
        };
    }
    if (itemType == URL.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getURL(name);
            }
        };
    }
    if (itemType == BigInteger.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                final BigDecimal res = rs.getBigDecimal(name);
                return res == null ? null : res.toBigInteger();
            }
        };
    }
    if (itemType == BigDecimal.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBigDecimal(name);
            }
        };
    }
    if (itemType == InputStream.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBinaryStream(name);
            }
        };
    }
    if (itemType == Boolean.class || itemType == Boolean.TYPE) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBoolean(name);
            }
        };
    }
    if (itemType == Blob.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getBlob(name);
            }
        };
    }
    if (itemType == java.sql.Date.class || itemType == java.util.Date.class) {
        return new ScalarRMF() {
            public Object map(ResultSet rs) throws SQLException {
                return rs.getTimestamp(name);
            }
        };
    }
    if (itemType instanceof Class) {
        final Class itemClass = (Class) itemType;
        final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass);
        if (columnMapper != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    return columnMapper.map(rs, name);
                }
            };
        }
        final Converter converter = ConvertUtils.lookup(itemClass);
        if (converter != null) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(name);
                    if (s == null) {
                        return null;
                    }
                    return converter.convert(itemClass, s);
                }
            };
        }
        if (Enum.class.isAssignableFrom((Class<?>) itemType)) {
            return new ScalarRMF() {
                public Object map(ResultSet rs) throws SQLException {
                    String s = rs.getString(name);
                    if (s == null) {
                        return null;
                    }
                    //noinspection unchecked
                    return Enum.valueOf((Class<Enum>) itemType, s);
                }
            };
        }
    }
    if (req) {
        throw new IllegalArgumentException("no mapping defined for " + itemType);
    }
    return null;
}

From source file:eionet.meta.dao.mysql.SchemaSetDAOImpl.java

/**
 * @see eionet.meta.dao.ISchemaSetDAO#getSchemaSetVersions(String, java.lang.String, int...)
 *//* w  w w . j a va2 s  .c o m*/
@Override
public List<SchemaSet> getSchemaSetVersions(String userName, String continuityId, int... excludeIds) {

    if (StringUtils.isBlank(continuityId)) {
        throw new IllegalArgumentException("Continuity id must not be blank!");
    }

    String sql = "select * from T_SCHEMA_SET where WORKING_COPY=false and CONTINUITY_ID=:continuityId";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("continuityId", continuityId);

    if (StringUtils.isBlank(userName)) {
        sql += " and REG_STATUS=:regStatus";
        params.put("regStatus", RegStatus.RELEASED.toString());
    }

    if (excludeIds != null && excludeIds.length > 0) {
        sql += " and SCHEMA_SET_ID not in (:excludeIds)";
        params.put("excludeIds", Arrays.asList(ArrayUtils.toObject(excludeIds)));
    }
    sql += " order by SCHEMA_SET_ID desc";

    List<SchemaSet> resultList = getNamedParameterJdbcTemplate().query(sql, params, new RowMapper<SchemaSet>() {
        @Override
        public SchemaSet mapRow(ResultSet rs, int rowNum) throws SQLException {
            SchemaSet ss = new SchemaSet();
            ss.setId(rs.getInt("SCHEMA_SET_ID"));
            ss.setIdentifier(rs.getString("IDENTIFIER"));
            ss.setContinuityId(rs.getString("CONTINUITY_ID"));
            ss.setRegStatus(RegStatus.fromString(rs.getString("REG_STATUS")));
            ss.setWorkingCopy(rs.getBoolean("WORKING_COPY"));
            ss.setWorkingUser(rs.getString("WORKING_USER"));
            ss.setDateModified(rs.getTimestamp("DATE_MODIFIED"));
            ss.setUserModified(rs.getString("USER_MODIFIED"));
            ss.setComment(rs.getString("COMMENT"));
            ss.setCheckedOutCopyId(rs.getInt("CHECKEDOUT_COPY_ID"));
            ss.setStatusModified(rs.getTimestamp("STATUS_MODIFIED"));
            return ss;
        }
    });

    return resultList;
}