Example usage for java.sql ResultSet getTimestamp

List of usage examples for java.sql ResultSet getTimestamp

Introduction

In this page you can find the example usage for java.sql ResultSet getTimestamp.

Prototype

java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;

Source Link

Document

Retrieves the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp object in the Java programming language.

Usage

From source file:com.github.dbourdette.glass.log.joblog.jdbc.JdbcJobLogStore.java

private JobLog doMapRow(ResultSet rs, int rowNum) throws SQLException {
    JobLog jobLog = new JobLog();

    jobLog.setExecutionId(rs.getLong("executionId"));
    jobLog.setLevel(JobLogLevel.valueOf(rs.getString("logLevel")));
    jobLog.setDate(rs.getTimestamp("logDate"));
    jobLog.setJobClass(rs.getString("jobClass"));
    jobLog.setJobGroup(rs.getString("jobGroup"));
    jobLog.setJobName(rs.getString("jobName"));
    jobLog.setTriggerGroup(rs.getString("triggerGroup"));
    jobLog.setTriggerName(rs.getString("triggerName"));
    jobLog.setMessage(rs.getString("message"));
    jobLog.setStackTrace(rs.getString("stackTrace"));
    jobLog.setRootCause(rs.getString("rootCause"));

    return jobLog;
}

From source file:com.adito.tunnels.JDBCTunnelDatabase.java

Tunnel buildTunnel(ResultSet rs) throws Exception {
    Timestamp cd = rs.getTimestamp("date_created");
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(cd == null ? System.currentTimeMillis() : cd.getTime());
    Timestamp ad = rs.getTimestamp("date_amended");
    Calendar a = Calendar.getInstance();
    a.setTimeInMillis(ad == null ? System.currentTimeMillis() : ad.getTime());
    return new DefaultTunnel(rs.getInt("realm_id"), rs.getString("name"), rs.getString("description"),
            rs.getInt("tunnel_id"), rs.getInt("type"), rs.getBoolean("auto_start"), rs.getString("transport"),
            rs.getString("username"), rs.getInt("source_port"),
            new HostService(rs.getString("destination_host"), rs.getInt("destination_port")),
            rs.getString("source_interface"), c, a);
}

From source file:tianci.pinao.dts.tasks.dao.impl.ConfigDaoImpl.java

@Override
public Map<Integer, Config> getConfigs() {
    final Map<Integer, Config> configs = new HashMap<Integer, Config>();
    getJdbcTemplate().query("select id, type, value, lastmod_time, lastmod_userid from "
            + SqlConstants.TABLE_CONFIG + " where isdel = ?", new Object[] { 0 }, new RowMapper<Config>() {

                @Override//from ww w  .  ja v a  2  s  .c o  m
                public Config mapRow(ResultSet rs, int index) throws SQLException {
                    Config config = new Config();

                    config.setId(rs.getInt("id"));
                    config.setType(rs.getInt("type"));
                    config.setValue(rs.getLong("value"));
                    Timestamp ts = rs.getTimestamp("lastmod_time");
                    if (ts != null)
                        config.setLastModTime(new Date(ts.getTime()));
                    config.setLastModUserid(rs.getInt("lastmod_userid"));

                    configs.put(config.getType(), config);

                    return config;
                }

            });

    return configs;
}

From source file:eionet.cr.dao.readers.StagingDatabaseDTOReader.java

@Override
public void readRow(ResultSet rs) throws SQLException, ResultSetReaderException {

    StagingDatabaseDTO databaseDTO = new StagingDatabaseDTO();
    databaseDTO.setId(rs.getInt("DATABASE_ID"));
    databaseDTO.setName(rs.getString("NAME"));
    databaseDTO.setCreator(rs.getString("CREATOR"));
    databaseDTO.setCreated(rs.getTimestamp("CREATED"));
    databaseDTO.setDescription(rs.getString("DESCRIPTION"));
    databaseDTO.setImportStatus(Enum.valueOf(ImportStatus.class, rs.getString("IMPORT_STATUS")));
    databaseDTO.setImportLog(rs.getString("IMPORT_LOG"));

    try {/*from  w w w. java 2  s .co m*/
        Blob blob = rs.getBlob("DEFAULT_QUERY");
        String query = blob == null ? null : blob.length() == 0 ? "" : IOUtils.toString(blob.getBinaryStream());
        databaseDTO.setDefaultQuery(query);
    } catch (Exception e) {
        LOGGER.warn("Failed to read column: DEFAULT_QUERY", e);
    }

    resultList.add(databaseDTO);
}

From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java

private HashMap<String, Long> buildHashMap(String sql) throws SQLException {
    Connection conn = databaseClient.getConnection();
    HashMap<String, Long> map = new HashMap<String, Long>();

    try {//  w  ww .  java  2  s .  co  m
        if (conn != null) {
            Statement stmnt = conn.createStatement();
            ResultSet rs = stmnt.executeQuery(sql);

            while (rs.next()) {
                String key = rs.getString(1);
                Long date_created = rs.getTimestamp(2).getTime();
                if (!map.containsKey(key)) {
                    map.put(key, date_created);
                }
            }
        }
    } finally {
        databaseClient.closeConnection(conn);
    }

    return map;

}

From source file:com.azaptree.services.domain.entity.dao.VersionedEntityRowMapperSupport.java

@Override
public T mapRow(final ResultSet rs, final int rowNum) throws SQLException {
    final T entity = createEntity(rs, rowNum);
    final DomainVersionedEntity domainEntity = (DomainVersionedEntity) entity;
    domainEntity.setEntityId((UUID) rs.getObject("entity_id"));
    domainEntity.setEntityVersion(rs.getLong("entity_version"));
    domainEntity.setEntityCreatedOn(rs.getTimestamp("entity_created_on").getTime());
    domainEntity.setCreatedBy((UUID) rs.getObject("entity_created_by"));
    domainEntity.setEntityUpdatedOn(rs.getTimestamp("entity_updated_on").getTime());
    domainEntity.setUpdatedBy((UUID) rs.getObject("entity_updated_by"));
    return mapRow(entity, rs, rowNum);
}

From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java

@Override
public Date getSettingModificationDate(final String key, final String type) {
    return getJdbcTemplate().query(new PreparedStatementCreator() {

        @Override//from  ww w . j av  a  2 s  .  c o  m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement stmt = con.prepareStatement(sqlGetDate);
            stmt.setMaxRows(1);
            stmt.setString(1, key);
            stmt.setString(2, type);
            return stmt;
        }
    }, new ResultSetExtractor<Date>() {

        @Override
        public Date extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (rs.next()) {
                return rs.getTimestamp(1);
            }
            return null;
        }
    });
}

From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java

@Override
public Date getMostRecentModificationDate() {
    return getJdbcTemplate().query(new PreparedStatementCreator() {

        @Override/*from  w w w .j  av a2s .co m*/
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement stmt = con.prepareStatement(sqlGetMostRecentDate);
            stmt.setMaxRows(1);
            final int mask = SettingFlag.maskForSet(EnumSet.of(SettingFlag.IgnoreModificationDate));
            stmt.setInt(1, mask);
            stmt.setInt(2, mask);
            return stmt;
        }
    }, new ResultSetExtractor<Date>() {

        @Override
        public Date extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (rs.next()) {
                return rs.getTimestamp(1);
            }
            return null;
        }
    });
}

From source file:net.bhira.sample.api.jdbc.CompanyRowMapper.java

/**
 * Constructor for CompanyRowMapper that creates an instance of
 * {@link net.bhira.sample.model.Company} from row represented by rowNum in the given ResultSet.
 * /*from  w  w  w  .j a v  a  2 s  .  c  o m*/
 * @param rs
 *            an instance of ResultSet to be processed.
 * @param rowNum
 *            integer representing the row number in ResultSet.
 */
@Override
public Company mapRow(ResultSet rs, int rowNum) throws SQLException {
    Company company = new Company();
    company.setId(rs.getLong("id"));
    company.setName(rs.getString("name"));
    company.setIndustry(rs.getString("industry"));
    company.setBillingAddress(rs.getString("billingaddr"));
    company.setShippingAddress(rs.getString("shippingaddr"));
    company.setCreated(rs.getTimestamp("created"));
    company.setModified(rs.getTimestamp("modified"));
    company.setCreatedBy(rs.getString("createdby"));
    company.setModifiedBy(rs.getString("modifiedby"));
    return company;
}

From source file:org.ohmage.query.impl.UserSurveyResponseQueries.java

/**
 * Retrieves the percentage of non-null location values from surveys over
 * the past 'hours'./*from  w  w  w  .  ja  va 2 s .  c  om*/
 * 
 * @param requestersUsername The username of the user that is requesting
 *                       this information.
 * 
 * @param usersUsername The username of the user to which the data belongs.
 * 
 * @param hours Defines the timespan for which the information should be
 *             retrieved. The timespan is from now working backwards until
 *             'hours' hours ago.
 * 
 * @return Returns the percentage of non-null location values from surveys
 *          over the last 'hours' or null if there were no surveys.
 */
public Double getPercentageOfNonNullSurveyLocations(String requestersUsername, String usersUsername, int hours)
        throws DataAccessException {

    long nonNullLocationsCount = 0;
    long totalLocationsCount = 0;

    try {
        // Get a time stamp from 24 hours ago.
        Calendar dayAgo = Calendar.getInstance();
        dayAgo.add(Calendar.HOUR_OF_DAY, -hours);
        final Timestamp dayAgoTimestamp = new Timestamp(dayAgo.getTimeInMillis());

        final List<String> nonNullLocations = new LinkedList<String>();
        final List<String> allLocations = new LinkedList<String>();

        getJdbcTemplate().query(SQL_GET_SURVEY_RESPONSES_FOR_USER_FOR_REQUESTER,
                new Object[] { usersUsername, requestersUsername }, new RowMapper<String>() {
                    @Override
                    public String mapRow(ResultSet rs, int rowNum) throws SQLException {
                        // Get the time the Mobility point was uploaded.
                        Timestamp generatedTimestamp = rs.getTimestamp("upload_timestamp");

                        // If it was uploaded within the last 'hours' it is
                        // valid.
                        if (!generatedTimestamp.before(dayAgoTimestamp)) {
                            String location = rs.getString("location");
                            if (location != null) {
                                nonNullLocations.add(location);
                            }
                            allLocations.add(location);
                        }

                        return null;
                    }
                });

        nonNullLocationsCount += nonNullLocations.size();
        totalLocationsCount += allLocations.size();
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException(
                "Error while executing '" + SQL_GET_SURVEY_RESPONSES_FOR_USER_FOR_REQUESTER
                        + "' with parameters: " + usersUsername + ", " + requestersUsername,
                e);
    }

    if (totalLocationsCount == 0) {
        return null;
    } else {
        return new Double(nonNullLocationsCount) / new Double(totalLocationsCount);
    }
}