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:esg.node.util.migrate.UserMigrationTool.java
public int migrateGroups() { int ret = 0;//from w w w .j a v a 2 s .c o m ResultSetHandler<Integer> groupsResultSetHandler = new ResultSetHandler<Integer>() { public Integer handle(ResultSet rs) throws SQLException { int i = 0; String groupName = transformGroupName(rs.getString(1)); while (rs.next()) { // [name] [description] [visible] [automatic_approval] if (UserMigrationTool.this.groupRoleDAO.addGroup(groupName, rs.getString(2), rs.getBoolean(3), rs.getBoolean(4))) { i++; System.out.println("Migrated group #" + i + ": " + groupName); } } return i; } }; try { ret = queryRunner.query(sourceGroupInfoQuery, groupsResultSetHandler); log.info("Migrated [" + ret + "] group records"); } catch (SQLException e) { e.printStackTrace(); } return ret; }
From source file:net.algem.security.UserDaoImpl.java
@Override public User find(String login) { String query = "SELECT l.idper,l.login,l.profil,per.nom,per.prenom,coalesce(prof.actif, false),coalesce(e.idper,0),coalesce(tech.idper,0)" + " FROM " + TABLE + " l INNER JOIN " + PersonIO.TABLE + " per ON (l.idper = per.id)" + " LEFT OUTER JOIN prof ON (l.idper = prof.idper)" + " LEFT OUTER JOIN eleve e ON (l.idper = e.idper)" + " LEFT OUTER JOIN technicien tech ON (l.idper = tech.idper)" + " WHERE trim(l.login) = ?"; return jdbcTemplate.queryForObject(query, new RowMapper<User>() { @Override/*from w ww. j a v a 2 s . c om*/ public User mapRow(ResultSet rs, int rowNum) throws SQLException { User u = new User(); u.setId(rs.getInt(1)); u.setLogin(getLoginFromStringResult(rs.getString(2))); u.setProfile(getProfileFromId(rs.getShort(3))); u.setName(rs.getString(4)); u.setFirstName(rs.getString(5)); u.setTeacher(rs.getBoolean(6));// active teachers only u.setStudent(rs.getInt(7) > 0); u.setTech(rs.getInt(8) > 0); return u; } }, login); }
From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java
@Override public Customer getById(int customerId) throws SQLException { return (Customer) jdbcTemplate.query(SQLConstant.CUSTOMER_GETBYID, new Object[] { customerId }, new ResultSetExtractor<Customer>() { @Override/*ww w. j a va 2s .c o m*/ public Customer extractData(ResultSet rs) throws SQLException, DataAccessException { Customer c = null; if (rs.next()) { c = new Customer(); c.setCustomerId(rs.getInt("customer_id")); c.setFirstName(rs.getString("first_name")); c.setLastName(rs.getString("last_name")); c.setEmail(rs.getString("email")); c.setContactNo(rs.getString("contact_no")); c.setUsername(rs.getString("username")); c.setPassword(rs.getString("password")); c.setAddedDate(rs.getDate("added_date")); c.setStatus(rs.getBoolean("status")); } return c; } }); }
From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java
@Override public Customer authenticate(String username, String password) { return (Customer) jdbcTemplate.query(SQLConstant.CUSTOMER_AUTHENTICATE, new Object[] { username, password }, new ResultSetExtractor<Customer>() { @Override//from ww w . ja v a2s .c om public Customer extractData(ResultSet rs) throws SQLException, DataAccessException { Customer c = null; if (rs.next()) { c = new Customer(); c.setCustomerId(rs.getInt("customer_id")); c.setFirstName(rs.getString("first_name")); c.setLastName(rs.getString("last_name")); c.setEmail(rs.getString("email")); c.setContactNo(rs.getString("contact_no")); c.setUsername(rs.getString("username")); c.setPassword(rs.getString("password")); c.setAddedDate(rs.getDate("added_date")); c.setStatus(rs.getBoolean("status")); } return c; } }); }
From source file:dk.netarkivet.harvester.datamodel.ScheduleDBDAO.java
/** * Read an existing schedule.//from ww w . j a va 2 s. com * * @param scheduleName the name of the schedule * @return The schedule read * @throws ArgumentNotValid if schedulename is null or empty * @throws UnknownID if the schedule doesn't exist */ public synchronized Schedule read(String scheduleName) { ArgumentNotValid.checkNotNullOrEmpty(scheduleName, "String scheduleName"); Connection c = HarvestDBConnection.get(); PreparedStatement s = null; try { s = c.prepareStatement("SELECT schedule_id, comments, startdate, " + "enddate, maxrepeats, timeunit, " + "numtimeunits, anytime, onminute, " + "onhour, ondayofweek, ondayofmonth, edition " + "FROM schedules WHERE name = ?"); s.setString(1, scheduleName); ResultSet rs = s.executeQuery(); if (!rs.next()) { throw new UnknownID("No schedule named '" + scheduleName + "' found"); } long id = rs.getLong(1); boolean isTimedSchedule; String comments = rs.getString(2); Date startdate = DBUtils.getDateMaybeNull(rs, 3); Date enddate = DBUtils.getDateMaybeNull(rs, 4); int maxrepeats = rs.getInt(5); isTimedSchedule = rs.wasNull(); int timeunit = rs.getInt(6); int numtimeunits = rs.getInt(7); boolean anytime = rs.getBoolean(8); Integer minute = DBUtils.getIntegerMaybeNull(rs, 9); Integer hour = DBUtils.getIntegerMaybeNull(rs, 10); Integer dayofweek = DBUtils.getIntegerMaybeNull(rs, 11); Integer dayofmonth = DBUtils.getIntegerMaybeNull(rs, 12); log.debug("Creating frequency for " + "(timeunit,anytime,numtimeunits,hour, minute, dayofweek," + "dayofmonth) = (" + timeunit + ", " + anytime + "," + numtimeunits + "," + minute + "," + hour + "," + dayofweek + "," + dayofmonth + "," + ")"); Frequency freq = Frequency.getNewInstance(timeunit, anytime, numtimeunits, minute, hour, dayofweek, dayofmonth); long edition = rs.getLong(13); final Schedule schedule; if (isTimedSchedule) { schedule = Schedule.getInstance(startdate, enddate, freq, scheduleName, comments); } else { schedule = Schedule.getInstance(startdate, maxrepeats, freq, scheduleName, comments); } schedule.setID(id); schedule.setEdition(edition); return schedule; } catch (SQLException e) { throw new IOFailure( "SQL error reading schedule " + scheduleName + "\n" + ExceptionUtils.getSQLExceptionCause(e), e); } finally { DBUtils.closeStatementIfOpen(s); HarvestDBConnection.release(c); } }
From source file:com.havoc.hotel.admin.dao.impl.CustomerDAOImpl.java
@Override public Customer getByUsername(String username) throws SQLException { return jdbcTemplate.query(SQLConstant.CUSTOMER_GETBYUSER, new Object[] { username }, new ResultSetExtractor<Customer>() { @Override//from ww w. j a va 2 s .c om public Customer extractData(ResultSet rs) throws SQLException, DataAccessException { Customer c = null; if (rs.next()) { c = new Customer(); c.setCustomerId(rs.getInt("customer_id")); c.setFirstName(rs.getString("first_name")); c.setLastName(rs.getString("last_name")); c.setEmail(rs.getString("email")); c.setContactNo(rs.getString("contact_no")); c.setUsername(rs.getString("username")); c.setPassword(rs.getString("password")); c.setAddedDate(rs.getDate("added_date")); c.setStatus(rs.getBoolean("status")); } return c; } }); }
From source file:com.adito.applications.JDBCApplicationShortcutDatabase.java
/** * @param rs/*from w w w . j av a2 s. c o m*/ * @return ApplicationShortcut * @throws Exception */ ApplicationShortcut buildShortcut(ResultSet resultSet) throws Exception { int resourceId = resultSet.getInt("resource_id"); String name = resultSet.getString("name"); String description = resultSet.getString("description"); String application = resultSet.getString("application"); Calendar dateCreated = JDBCUtil.getCalendar(resultSet, "date_created"); Calendar dateAmended = JDBCUtil.getCalendar(resultSet, "date_amended"); int realmId = resultSet.getInt("realm_id"); boolean autoStart = resultSet.getBoolean("auto_start"); Map<String, String> settings = getParameters(resourceId); return new DefaultApplicationShortcut(realmId, resourceId, name, description, dateCreated, dateAmended, application, settings, autoStart); }
From source file:org.miloss.fgsms.services.rs.impl.reports.AvailabilityByService.java
private List<StatusRecordsExt> getStatusRecords(String url, TimeRange range, Connection con) { List<StatusRecordsExt> ret = new ArrayList<StatusRecordsExt>(); //first get the record just before the start of the range, if it exists PreparedStatement com = null; ResultSet rs = null; try {/* w w w.j a va 2 s . c o m*/ com = con.prepareStatement( "select status from availability where uri=? and utcdatetime < ? order by utcdatetime desc limit 1;"); com.setString(1, url); com.setLong(2, range.getStart().getTimeInMillis()); rs = com.executeQuery(); if (rs.next()) { //add a record for the exact start time of the range StatusRecordsExt x = new StatusRecordsExt(); x.gcal = new GregorianCalendar(); x.gcal.setTimeInMillis(range.getStart().getTimeInMillis()); x.status = rs.getBoolean("status"); ret.add(x); } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); } try { //get everything within the range com = con.prepareStatement( "select * from availability where uri=? and utcdatetime >= ? and utcdatetime <=? order by utcdatetime asc;"); com.setString(1, url); com.setLong(2, range.getStart().getTimeInMillis()); com.setLong(3, range.getEnd().getTimeInMillis()); rs = com.executeQuery(); boolean lastStatus = true; while (rs.next()) { //in order to produce a square wave style chart, inject an additional point for this time-1 for the same status //as the previous item if (!ret.isEmpty()) { StatusRecordsExt get = ret.get(ret.size() - 1); StatusRecordsExt x = new StatusRecordsExt(); x.gcal = new GregorianCalendar(); x.gcal.setTimeInMillis(rs.getLong("utcdatetime") - 1); x.status = get.status; ret.add(x); } StatusRecordsExt x = new StatusRecordsExt(); x.gcal = new GregorianCalendar(); x.gcal.setTimeInMillis(rs.getLong("utcdatetime")); x.status = rs.getBoolean("status"); lastStatus = x.status; ret.add(x); } StatusRecordsExt x = new StatusRecordsExt(); x.gcal = new GregorianCalendar(); x.gcal.setTimeInMillis(range.getEnd().getTimeInMillis()); x.status = lastStatus; ret.add(x); //getting the next record isn't important in this case as we are only interested in data within the range. return ret; } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); } return null; }
From source file:net.sourceforge.vulcan.spring.jdbc.BuildQuery.java
@Override protected JdbcBuildOutcomeDto mapRow(ResultSet rs, int rowNumber) throws SQLException { final JdbcBuildOutcomeDto dto = new JdbcBuildOutcomeDto(); dto.setPrimaryKey(rs.getInt("id")); dto.setName(rs.getString("name")); dto.setId(UUID.fromString(rs.getString("uuid"))); dto.setStatus(ProjectStatusDto.Status.valueOf(rs.getString("status"))); dto.setMessageKey(rs.getString("message_key")); dto.setBuildReasonKey(rs.getString("build_reason_key")); dto.setStartDate(new Date(rs.getTimestamp("start_date").getTime())); dto.setCompletionDate(new Date(rs.getTimestamp("completion_date").getTime())); dto.setBuildNumber(rs.getInt("build_number")); dto.setWorkDir(rs.getString("work_dir")); dto.setWorkDirSupportsIncrementalUpdate(rs.getBoolean("work_dir_vcs_clean")); dto.setTagName(rs.getString("tag_name")); dto.setRepositoryUrl(rs.getString("repository_url")); dto.setScheduledBuild(rs.getBoolean("scheduled_build")); dto.setStatusChanged(rs.getBoolean("status_changed")); dto.setRequestedBy(rs.getString("requested_by")); dto.setBrokenBy(rs.getString("broken_by_user_name")); final Timestamp claimed_date = rs.getTimestamp("claimed_date"); if (StringUtils.isNotBlank(dto.getBrokenBy()) && !rs.wasNull()) { dto.setClaimDate(new Date(claimed_date.getTime())); }/* w ww .j a v a2 s . co m*/ final String updateTypeString = rs.getString("update_type"); if (!rs.wasNull() && StringUtils.isNotEmpty(updateTypeString)) { dto.setUpdateType(ProjectStatusDto.UpdateType.valueOf(updateTypeString)); } else { dto.setUpdateType(null); } final Integer lastGoodBuildNumber = rs.getInt("last_good_build_number"); if (!rs.wasNull()) { dto.setLastGoodBuildNumber(lastGoodBuildNumber); } final Long revision = rs.getLong("revision"); if (!rs.wasNull()) { final RevisionTokenDto revisionTokenDto = new RevisionTokenDto(revision, rs.getString("revision_label")); if (rs.getBoolean("revision_unavailable")) { dto.setLastKnownRevision(revisionTokenDto); } else { dto.setRevision(revisionTokenDto); } } dto.setMessageArgs(mapMessageArgs(rs, "message_arg_")); dto.setBuildReasonArgs(mapMessageArgs(rs, "build_reason_arg_")); return dto; }
From source file:com.ewcms.component.interaction.dao.InteractionDAO.java
private Interaction interactionRowMapper(ResultSet rs) throws SQLException { Interaction vo = new Interaction(); vo.setId(rs.getInt("id")); vo.setUsername(rs.getString("username")); vo.setTitle(rs.getString("title")); vo.setContent(rs.getString("content")); vo.setReplay(rs.getString("replay")); vo.setType(rs.getInt("type")); vo.setState(InteractionState.values()[rs.getInt("state")]); vo.setIp(rs.getString("ip")); vo.setChecked(rs.getBoolean("checked")); vo.setDate(rs.getTimestamp("date")); vo.setReplayDate(rs.getTimestamp("replay_date")); vo.setCounter(rs.getInt("counter")); vo.setName(rs.getString("name")); Organ organ = new Organ(rs.getInt("organ_id"), rs.getString("organ_name")); vo.setOrgan(organ);//from w w w . ja v a 2 s. c o m return vo; }