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:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadFrom(Connection connection, Instant time) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" >= ? ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event);/*from w w w . ja v a 2s . co m*/ } } return events; }
From source file:org.ulyssis.ipp.snapshot.Event.java
public static List<Event> loadAfter(Connection connection, Instant time, long id) throws SQLException, IOException { String statement = "SELECT \"id\",\"data\",\"removed\" FROM \"events\" " + "WHERE \"time\" > ? OR (\"time\" = ? AND \"id\" > ?) ORDER BY \"time\" ASC, \"id\" ASC"; List<Event> events = new ArrayList<>(); try (PreparedStatement stmt = connection.prepareStatement(statement)) { stmt.setTimestamp(1, Timestamp.from(time)); stmt.setTimestamp(2, Timestamp.from(time)); stmt.setLong(3, id);//from ww w . j av a 2 s. c o m LOG.debug("Executing query: {}", stmt); ResultSet rs = stmt.executeQuery(); while (rs.next()) { String evString = rs.getString("data"); Event event = Serialization.getJsonMapper().readValue(evString, Event.class); event.id = rs.getLong("id"); event.removed = rs.getBoolean("removed"); events.add(event); } } LOG.debug("Loaded {} events", events.size()); return events; }
From source file:com.sql.CaseType.java
/** * Gathers a list of active case types for finding the proper section based * on the case number.//from w w w .ja v a 2 s . c o m * * @param section For which section the method is currently processing * @return List CaseTypeModel */ public static List<CaseTypeModel> getCaseTypesBySection(String section) { List<CaseTypeModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM CaseType WHERE active = 1 AND section = ?"; ps = conn.prepareStatement(sql); ps.setString(1, section); rs = ps.executeQuery(); while (rs.next()) { CaseTypeModel item = new CaseTypeModel(); item.setId(rs.getInt("id")); item.setActive(rs.getBoolean("active")); item.setSection(rs.getString("Section")); item.setCaseType(rs.getString("caseType")); item.setDescription(rs.getString("Description")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:tds.assessment.repositories.impl.StrandQueryRepositoryImpl.java
private static Strand buildStrandFromResultSet(final ResultSet rs) throws SQLException { return new Strand.Builder().withName(rs.getString("name")).withKey(rs.getString("_key")) .withMinItems(rs.getInt("minitems")).withMaxItems(rs.getInt("maxitems")) // calling getObject() and casting to Float because .getFloat() defaults to 0 if null .withAdaptiveCut((Float) rs.getObject("adaptivecut")).withSegmentKey(rs.getString("segmentKey")) .withStrictMax(rs.getBoolean("isstrictmax")).withBpWeight(rs.getFloat("bpweight")) .withStartInfo((Float) rs.getObject("startInfo")).withScalar((Float) rs.getObject("scalar")) .withPrecisionTarget((Float) rs.getObject("precisionTarget")) .withPrecisionTargetMetWeight((Float) rs.getObject("precisionTargetMetWeight")) .withPrecisionTargetNotMetWeight((Float) rs.getObject("precisionTargetNotMetWeight")).build(); }
From source file:las.DBConnector.java
public static ArrayList<Member> getMemberTableIntoList() throws SQLException, ClassNotFoundException { ArrayList<Member> mtable = new ArrayList<>(); String data = "SELECT * FROM LAS.MEMBERS"; PreparedStatement pt = conn.prepareStatement(data); ResultSet rs = pt.executeQuery(); while (rs.next()) { mtable.add(new Member(rs.getInt("MEMBER_ID"), rs.getString("NAME"), rs.getString("EMAIL"), rs.getString("PRIVILEGE"), rs.getBoolean("ISSTAFF"))); }/* w w w.j a v a2 s. c o m*/ return mtable; }
From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java
public static synchronized Token getAccessToken(final String tokenStr) { Token tokenObj = DbPoolServlet.goSql("Get oauth token", "select access_token, token_secret, consumer_key, callback_url, identity, container_name, accessor_write_permission, share_id " + "from oauth_accessors " + "join oauth_consumers on oauth_consumers.consumer_id = oauth_accessors.consumer_id " + "left outer join containers on containers.container_id = oauth_accessors.container_id " + "left outer join container_shares on oauth_accessors.share_key = container_shares.share_key " + "left outer join users on users.user_id = containers.user_id " + "left outer join user_identities on users.user_id = user_identities.user_id " + "where access_token = ? limit 1", new SqlWorker<Token>() { @Override/*from w w w. j a v a 2 s.c o m*/ public Token go(Connection conn, PreparedStatement stmt) throws SQLException { Token token = null; stmt.setString(1, tokenStr); ResultSet rs = stmt.executeQuery(); if (rs.next()) { Set<USER_ROLES> rolesSet = new HashSet<USER_ROLES>(); if (null == rs.getString("share_id")) { rolesSet.add(USER_ROLES.user); } else { if (rs.getBoolean("accessor_write_permission")) rolesSet.add(USER_ROLES.rwshareuser); else rolesSet.add(USER_ROLES.roshareuser); } token = new Token(rs.getString("access_token"), rs.getString("token_secret"), rs.getString("consumer_key"), rs.getString("callback_url"), new SciDriveUser(rs.getString("identity"), rs.getString("container_name"), rs.getBoolean("accessor_write_permission")), rolesSet, new MultivaluedMapImpl()); } return token; } }); return tokenObj; }
From source file:com.wso2.raspberrypi.Util.java
private static RaspberryPi toRaspberryPi(ResultSet rs) throws SQLException { RaspberryPi pi = new RaspberryPi(); pi.setMacAddress(rs.getString("mac")); pi.setIpAddress(rs.getString("ip")); pi.setLastUpdated(rs.getLong("last_updated")); pi.setLabel(rs.getString("label")); pi.setReservedFor(rs.getString("owner")); pi.setBlink(rs.getBoolean("blink")); pi.setReboot(rs.getBoolean("reboot")); pi.setSelected(rs.getBoolean("selected")); return pi;/* w ww. jav a 2s. c o m*/ }
From source file:com.app.dao.SearchQueryDAO.java
private static SearchQuery _createSearchQueryFromResultSet(ResultSet resultSet) throws SQLException { SearchQuery searchQuery = new SearchQuery(); searchQuery.setSearchQueryId(resultSet.getInt("searchQueryId")); searchQuery.setUserId(resultSet.getInt("userId")); searchQuery.setKeywords(resultSet.getString("keywords")); searchQuery.setCategoryId(resultSet.getString("categoryId")); searchQuery.setSubcategoryId(resultSet.getString("subcategoryId")); searchQuery.setSearchDescription(resultSet.getBoolean("searchDescription")); searchQuery.setFreeShippingOnly(resultSet.getBoolean("freeShippingOnly")); searchQuery.setNewCondition(resultSet.getBoolean("newCondition")); searchQuery.setUsedCondition(resultSet.getBoolean("usedCondition")); searchQuery.setUnspecifiedCondition(resultSet.getBoolean("unspecifiedCondition")); searchQuery.setAuctionListing(resultSet.getBoolean("auctionListing")); searchQuery.setFixedPriceListing(resultSet.getBoolean("fixedPriceListing")); searchQuery.setMaxPrice(resultSet.getDouble("maxPrice")); searchQuery.setMinPrice(resultSet.getDouble("minPrice")); searchQuery.setGlobalId(resultSet.getString("globalId")); searchQuery.setActive(resultSet.getBoolean("active")); return searchQuery; }
From source file:cn.clickvalue.cv2.model.rowmapper.BeanPropertyRowMapper.java
/** * Retrieve a JDBC column value from a ResultSet, using the specified value type. * <p>Uses the specifically typed ResultSet accessor methods, falling back to * {@link #getResultSetValue(java.sql.ResultSet, int)} for unknown types. * <p>Note that the returned value may not be assignable to the specified * required type, in case of an unknown type. Calling code needs to deal * with this case appropriately, e.g. throwing a corresponding exception. * @param rs is the ResultSet holding the data * @param index is the column index/*from w w w.j av a 2s . c o m*/ * @param requiredType the required value type (may be <code>null</code>) * @return the value object * @throws SQLException if thrown by the JDBC API */ public static Object getResultSetValue(ResultSet rs, int index, Class requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } Object value = null; boolean wasNullCheck = false; // Explicitly extract typed value, as far as possible. if (String.class.equals(requiredType)) { value = rs.getString(index); } else if (boolean.class.equals(requiredType) || Boolean.class.equals(requiredType)) { value = Boolean.valueOf(rs.getBoolean(index)); wasNullCheck = true; } else if (byte.class.equals(requiredType) || Byte.class.equals(requiredType)) { value = Byte.valueOf(rs.getByte(index)); wasNullCheck = true; } else if (short.class.equals(requiredType) || Short.class.equals(requiredType)) { value = Short.valueOf(rs.getShort(index)); wasNullCheck = true; } else if (int.class.equals(requiredType) || Integer.class.equals(requiredType)) { value = Integer.valueOf(rs.getInt(index)); wasNullCheck = true; } else if (long.class.equals(requiredType) || Long.class.equals(requiredType)) { value = Long.valueOf(rs.getLong(index)); wasNullCheck = true; } else if (float.class.equals(requiredType) || Float.class.equals(requiredType)) { value = Float.valueOf(rs.getFloat(index)); wasNullCheck = true; } else if (double.class.equals(requiredType) || Double.class.equals(requiredType) || Number.class.equals(requiredType)) { value = Double.valueOf(rs.getDouble(index)); wasNullCheck = true; } else if (byte[].class.equals(requiredType)) { value = rs.getBytes(index); } else if (java.sql.Date.class.equals(requiredType)) { value = rs.getDate(index); } else if (java.sql.Time.class.equals(requiredType)) { value = rs.getTime(index); } else if (java.sql.Timestamp.class.equals(requiredType) || java.util.Date.class.equals(requiredType)) { value = rs.getTimestamp(index); } else if (BigDecimal.class.equals(requiredType)) { value = rs.getBigDecimal(index); } else if (Blob.class.equals(requiredType)) { value = rs.getBlob(index); } else if (Clob.class.equals(requiredType)) { value = rs.getClob(index); } else { // Some unknown type desired -> rely on getObject. value = getResultSetValue(rs, index); } // Perform was-null check if demanded (for results that the // JDBC driver returns as primitives). if (wasNullCheck && value != null && rs.wasNull()) { value = null; } return value; }
From source file:com.keybox.manage.db.ProfileSystemsDB.java
/** * returns a list of systems for a given profile * * @param con DB connection//from www . j a va2s. c o m * @param profileId profile id * @return list of host systems */ public static List<HostSystem> getSystemsByProfile(Connection con, Long profileId) { List<HostSystem> hostSystemList = new ArrayList<HostSystem>(); try { PreparedStatement stmt = con.prepareStatement( "select * from system s, system_map m where s.id=m.system_id and m.profile_id=? order by display_nm asc"); stmt.setLong(1, profileId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { HostSystem hostSystem = new HostSystem(); hostSystem.setId(rs.getLong("id")); hostSystem.setDisplayNm(rs.getString("display_nm")); hostSystem.setUser(rs.getString("user")); hostSystem.setHost(rs.getString("host")); hostSystem.setPort(rs.getInt("port")); hostSystem.setAuthorizedKeys(rs.getString("authorized_keys")); hostSystem.setEnabled(rs.getBoolean("enabled")); hostSystemList.add(hostSystem); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { e.printStackTrace(); } return hostSystemList; }