List of usage examples for java.sql ResultSet getBoolean
boolean getBoolean(String columnLabel) throws SQLException;
ResultSet
object as a boolean
in the Java programming language. From source file:com.emc.ecs.sync.service.DbService.java
protected boolean hasBooleanColumn(ResultSet rs, String name) throws SQLException { if (hasColumn(rs, name)) { rs.getBoolean(name); return !rs.wasNull(); }/*from ww w. j a v a 2 s .c o m*/ return false; }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @return sorted script list/*www . j a va 2 s .c om*/ */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { ArrayList<PublicKey> publicKeysList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:com.norconex.collector.core.data.store.impl.jdbc.BasicJDBCSerializer.java
@Override public ICrawlData toCrawlData(String table, ResultSet rs) throws SQLException { if (rs == null) { return null; }/*w w w . java 2s. com*/ BaseCrawlData data = new BaseCrawlData(); data.setReference(rs.getString("reference")); data.setParentRootReference(rs.getString("parentRootReference")); data.setRootParentReference(rs.getBoolean("isRootParentReference")); data.setState(CrawlState.valueOf(rs.getString("state"))); data.setMetaChecksum(rs.getString("metaChecksum")); data.setContentChecksum(rs.getString("contentChecksum")); String contentType = rs.getString("contentType"); if (StringUtils.isNoneBlank(contentType)) { data.setContentType(ContentType.valueOf(contentType)); } long crawlDate = rs.getLong("crawlDate"); if (crawlDate > 0) { data.setCrawlDate(new Date(crawlDate)); } return data; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @return sorted script list//from w w w .j ava 2 s .c o m */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { ArrayList<PublicKey> publicKeysList = new ArrayList<PublicKey>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = " order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i++, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:com.dsclab.loader.export.DBClient.java
public List<Attribute_annotations> getAttributesAnnotations(int key) throws SQLException { ResultSet rs = stmt.executeQuery("select * from attribute_annotations where pathid = " + key); List<Attribute_annotations> saveAttributeAnnotations = new ArrayList<>(); while (rs.next()) { saveAttributeAnnotations.add(new Attribute_annotations(rs.getInt("attributeid"), rs.getInt("frame"), rs.getBoolean("value"))); }/*w w w . j a v a 2s.c o m*/ return saveAttributeAnnotations; }
From source file:com.wso2telco.proxy.util.DBUtils.java
/** * Get a map of parameters mapped to a scope * * @return map of scope vs parameters//from w ww .j a va 2s . c o m * @throws AuthenticatorException on errors */ public static Map<String, ScopeParam> getScopeParams(String scope) throws AuthenticatorException { Connection conn = null; PreparedStatement ps = null; ResultSet results = null; String[] scopeValues = scope.split("\\s+|\\+"); StringBuilder params = new StringBuilder("?"); for (int i = 1; i < scopeValues.length; i++) { params.append(",?"); } String sql = "SELECT * FROM `scope_parameter` WHERE scope in (" + params + ")"; if (log.isDebugEnabled()) { log.debug("Executing the query " + sql); } Map scopeParamsMap = new HashMap(); try { conn = getConnectDBConnection(); ps = conn.prepareStatement(sql); for (int i = 0; i < scopeValues.length; i++) { ps.setString(i + 1, scopeValues[i]); } results = ps.executeQuery(); Boolean mainScopeFound = false; List<String> scopeValuesFromDatabase = new ArrayList<>(); while (results.next()) { Boolean isMultiscope = results.getBoolean("is_multiscope"); scopeValuesFromDatabase.add(results.getString("scope")); if (!isMultiscope) { //throw error if multiple main scopes found if (mainScopeFound) { throw new ConfigurationException("Multiple main scopes found"); } //mark as main scope found mainScopeFound = true; scopeParamsMap.put("scope", results.getString("scope")); ScopeParam parameters = new ScopeParam(); parameters.setScope(results.getString("scope")); parameters.setLoginHintMandatory(results.getBoolean("is_login_hint_mandatory")); parameters.setHeaderMsisdnMandatory(results.getBoolean("is_header_msisdn_mandatory")); parameters.setMsisdnMismatchResult(ScopeParam.msisdnMismatchResultTypes .valueOf(results.getString("msisdn_mismatch_result"))); parameters.setHeFailureResult( ScopeParam.heFailureResults.valueOf(results.getString("he_failure_result"))); parameters.setTncVisible(results.getBoolean("is_tnc_visible")); parameters.setLoginHintFormat(getLoginHintFormatTypeDetails(results.getInt("param_id"), conn)); scopeParamsMap.put("params", parameters); } } //validate all scopes and compare with scopes fetched from database for (String scopeToValidate : scopeValues) { if (!scopeValuesFromDatabase.contains(scopeToValidate)) { throw new ConfigurationException("One or more scopes are not valid"); } } } catch (SQLException e) { handleException("Error occurred while getting scope parameters from the database", e); } catch (ConfigurationException e) { handleException(e.getMessage(), e); } catch (NamingException e) { log.error("Naming exception ", e); } finally { closeAllConnections(ps, conn, results); } return scopeParamsMap; }
From source file:com.flexive.core.storage.MySQL.MySQLSequencerStorage.java
/** * {@inheritDoc}/*from w w w . jav a 2s.c o m*/ */ @Override public List<CustomSequencer> getCustomSequencers() throws FxApplicationException { List<CustomSequencer> res = new ArrayList<CustomSequencer>(20); Connection con = null; PreparedStatement ps = null; try { con = Database.getDbConnection(); ps = con.prepareStatement(SQL_GET_USER); ResultSet rs = ps.executeQuery(); while (rs != null && rs.next()) res.add(new CustomSequencer(rs.getString(1), rs.getBoolean(2), rs.getLong(3))); } catch (SQLException exc) { throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()); } finally { Database.closeObjects(MySQLSequencerStorage.class, con, ps); } return res; }
From source file:de.nim.wscr.dao.MemberDAO.java
@Override public Member getMember(Member member) { Member toSearchForMember = new Member(); if (null != member) { try {// w ww . j a va2 s. com String sql = "SELECT * FROM db1. member WHERE "; int paramCount = 0; if (member.getId() != null) { sql = sql + " ID = " + member.getId(); paramCount++; } if (StringUtils.isNotEmpty(member.getFirstName())) { if (paramCount > 0) { sql = sql + " AND"; } sql = sql + " FIRST_NAME = " + member.getFirstName(); paramCount++; } if (StringUtils.isNotEmpty(member.getLastName())) { if (paramCount > 0) { sql = sql + " AND"; } sql = sql + " LAST_NAME = " + member.getLastName(); paramCount++; } ResultSet rs = connection.createStatement().executeQuery(sql); if (rs.next()) { toSearchForMember.setFirstName(rs.getString("FIRST_NAME")); toSearchForMember.setLastName(rs.getString("LAST_NAME")); toSearchForMember.setDriverLicense(rs.getBoolean("LICENSE")); toSearchForMember.setId(rs.getLong("ID")); } } catch (SQLException e) { throw new RuntimeException(e); } } return toSearchForMember; }
From source file:com.leapfrog.SpringMaven.DAOImpl.UserDAOImpl.java
@Override public List<User> getAll() throws SQLException, ClassNotFoundException { String query = "SELECT * from tbl_user"; return jdbcTemplate.query(query, new RowMapper<User>() { @Override//from w w w . ja v a 2 s . c o m public User mapRow(ResultSet rs, int i) throws SQLException { User user = new User(); user.setId(rs.getInt("user_id")); user.setUserName(rs.getString("user_name")); user.setPassword(rs.getString("password")); user.setEmail(rs.getString("email")); user.setStatus(rs.getBoolean("status")); return user; } }); }
From source file:com.leapfrog.SpringMaven.DAOImpl.UserDAOImpl.java
@Override public User getById(int id) throws SQLException, ClassNotFoundException { String query = "SELECT * from tbl_user where user_id=?"; return jdbcTemplate.queryForObject(query, new Object[] { id }, new RowMapper<User>() { @Override//from ww w. j a v a 2s . co m public User mapRow(ResultSet rs, int i) throws SQLException { User user = new User(); user.setId(rs.getInt("user_id")); user.setUserName(rs.getString("user_name")); user.setPassword(rs.getString("password")); user.setEmail(rs.getString("email")); user.setStatus(rs.getBoolean("status")); return user; } }); }