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:info.naiv.lab.java.tool.sqlite.exporter.component.ValueHandlerImpl.java

/**
 *
 * @param field/*from  w  w w.j a v a2s.  co  m*/
 * @param rowSet
 * @return
 * @throws SQLException
 */
@Override
public Object handleValue(Field field, ResultSet rowSet) throws SQLException {
    String name = field.getOriginalName();
    switch (field.getTypeInfo()) {
    case CHAR:
    case NCHAR:
        return StringUtils.trimTrailingWhitespace(rowSet.getString(name));
    case DATE:
        return Objects.toString(rowSet.getDate(name), null);
    case TIME:
        return Objects.toString(rowSet.getTime(name), null);
    case TIMESTAMP:
        return Objects.toString(rowSet.getTimestamp(name), null);
    default:
        return rowSet.getObject(name);
    }
}

From source file:com.springsource.greenhouse.events.load.JdbcEventLoaderRepositoryTest.java

@Test
public void updateTimeSlot() throws SQLException {
    long eventId = eventLoaderRepository.loadEvent(
            new EventData(1, "Test Event", "Test Event Description", "test", "2012-10-15T00:00:00",
                    "2012-10-18T23:59:59", "America/New_York", "NFJS", 297),
            new VenueData("Some Fancy Hotel", "1234 North Street, Chicago, IL 60605", 41.89001, -87.677765,
                    "It's in Illinois"));

    long timeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot 1",
            "2012-10-15T00:00:00", "2012-10-18T23:59:59", "NFJS", 6296));
    assertEquals(1L, timeSlotId);/*from  w w w  .  j  av a2  s. c  o m*/
    jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?",
            new RowMapper<ResultSet>() {
                public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    assertEquals(1L, rs.getLong("id"));
                    assertEquals(1L, rs.getLong("event"));
                    Timestamp startTime = rs.getTimestamp("startTime");
                    Timestamp endTime = rs.getTimestamp("endTime");
                    //            assertEquals(new DateTime(2012, 10, 15, 0, 0, 0, 0, DateTimeZone.getDefault()).getMillis(), startTime.getTime());
                    //            assertEquals(new DateTime(2012, 10, 18, 23, 59, 59, 0, DateTimeZone.getDefault()).getMillis(), endTime.getTime());
                    return null;
                }
            }, timeSlotId);

    long updatedTimeSlotId = eventLoaderRepository.loadTimeSlot(new TimeSlotData(eventId, "Time Slot One",
            "2012-10-15T01:00:00", "2012-10-15T02:30:00", "NFJS", 6296));
    assertEquals(1L, updatedTimeSlotId);
    jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?",
            new RowMapper<ResultSet>() {
                public ResultSet mapRow(ResultSet rs, int rowNum) throws SQLException {
                    assertEquals(1L, rs.getLong("id"));
                    assertEquals(1L, rs.getLong("event"));
                    assertEquals("Time Slot One", rs.getString("label"));
                    Timestamp startTime = rs.getTimestamp("startTime");
                    Timestamp endTime = rs.getTimestamp("endTime");
                    //            assertEquals(new DateTime(2012, 10, 15, 1, 0, 0, 0, DateTimeZone.getDefault()).getMillis(), startTime.getTime());
                    //            assertEquals(new DateTime(2012, 10, 15, 2, 30, 0, 0, DateTimeZone.getDefault()).getMillis(), endTime.getTime());
                    return null;
                }
            }, updatedTimeSlotId);
}

From source file:com.adanac.module.blog.dao.AnswerDao.java

public Map<String, String> transfer(ResultSet resultSet, ViewMode viewMode) {
    Map<String, String> comment = new HashMap<String, String>();
    try {/* w ww .  j  av a2  s  .c  o  m*/
        comment.put("id", resultSet.getString("id"));
        comment.put("answer", resultSet.getString("answer"));
        comment.put("answer_date",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(resultSet.getTimestamp("answer_date")));
        String username = resultSet.getString("username");
        if (!StringUtils.isEmpty(username)) {
            comment.put("answerer", username);
        } else {
            comment.put("answerer", resultSet.getString("city") + "?");
        }
        comment.put("good_times", resultSet.getString("good_times"));
        comment.put("bad_times", resultSet.getString("bad_times"));
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    return comment;
}

From source file:henu.dao.impl.CaclDaoImpl.java

@Override
public List<Cacl> getCacList(String uid) {
    String sql = "select * from cacl where author = " + uid;
    System.out.println(sql);/*from w w w  . ja va  2 s. c o  m*/

    ResultSet rs = SqlDB.executeQuery(sql);
    List<Cacl> list = new ArrayList<Cacl>();
    try {
        while (rs.next()) {
            Cacl cacl = new Cacl();
            cacl.setTid(rs.getLong("cid"));
            cacl.setName(rs.getString("cname"));
            cacl.setPostime(rs.getTimestamp("postime").toString());
            cacl.setStructure(rs.getString("structure"));
            cacl.setAuthor(Integer.parseInt(uid));
            cacl.setUsers(getCaclUserList(Long.toString(rs.getLong("cid"))));
            list.add(cacl);
        }
    } catch (SQLException ex) {

    }

    SqlDB.close();

    return list;
}

From source file:ru.org.linux.edithistory.EditHistoryDao.java

/**
 *     /?.//ww w  .  j  a  v  a2s.c o  m
 *
 * @param id id 
 * @param objectTypeEnum :   
 * @return ??  
 */
public List<EditHistoryDto> getEditInfo(int id, EditHistoryObjectTypeEnum objectTypeEnum) {
    final List<EditHistoryDto> editInfoDTOs = new ArrayList<>();
    jdbcTemplate.query(queryEditInfo, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            EditHistoryDto editHistoryDto = new EditHistoryDto();
            editHistoryDto.setId(resultSet.getInt("id"));
            editHistoryDto.setMsgid(resultSet.getInt("msgid"));
            editHistoryDto.setEditor(resultSet.getInt("editor"));
            editHistoryDto.setOldmessage(resultSet.getString("oldmessage"));
            editHistoryDto.setEditdate(resultSet.getTimestamp("editdate"));
            editHistoryDto.setOldtitle(resultSet.getString("oldtitle"));
            editHistoryDto.setOldtags(resultSet.getString("oldtags"));
            editHistoryDto.setObjectType(resultSet.getString("object_type"));

            editHistoryDto.setOldimage(resultSet.getInt("oldimage"));
            if (resultSet.wasNull()) {
                editHistoryDto.setOldimage(null);
            }

            editHistoryDto.setOldminor(resultSet.getBoolean("oldminor"));
            if (resultSet.wasNull()) {
                editHistoryDto.setOldminor(null);
            }

            editInfoDTOs.add(editHistoryDto);
        }
    }, id, objectTypeEnum.toString());
    return editInfoDTOs;
}

From source file:org.aksw.gerbil.database.ExperimentTaskResultRowMapper.java

@Override
public ExperimentTaskResult mapRow(ResultSet resultSet, int rowId) throws SQLException {
    return new ExperimentTaskResult(resultSet.getString(1), resultSet.getString(2),
            ExperimentType.valueOf(resultSet.getString(3)), Matching.valueOf(resultSet.getString(4)),
            new double[] { resultSet.getDouble(5), resultSet.getDouble(6), resultSet.getDouble(7),
                    resultSet.getDouble(8), resultSet.getDouble(9), resultSet.getDouble(10) },
            resultSet.getInt(11), resultSet.getInt(12), resultSet.getTimestamp(13).getTime());
}

From source file:org.jrecruiter.service.migration.impl.MigrationServiceImpl.java

private Statistic getStatistic(Long oldJobId) {

    final String sql = "select counter, last_access, unique_visits "
            + "from statistics where statistics.job_id = ?";

    ParameterizedRowMapper<Statistic> mapper = new ParameterizedRowMapper<Statistic>() {

        public Statistic mapRow(ResultSet rs, int rowNum) throws SQLException {
            Statistic statistic = new Statistic();
            statistic.setCounter(rs.getLong("unique_visits"));
            statistic.setLastAccess(rs.getTimestamp("last_access"));

            return statistic;
        }//from  w w w. ja va  2s. c  om
    };

    return this.jdbcTemplateV1.queryForObject(sql, mapper, oldJobId);

}

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

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

    HarvestSourceDTO harvestSourceDTO = new HarvestSourceDTO();
    harvestSourceDTO.setSourceId(new Integer(rs.getInt("HARVEST_SOURCE_ID")));
    harvestSourceDTO.setUrl(rs.getString("URL"));
    harvestSourceDTO.setUrlHash(Long.valueOf(rs.getLong("URL_HASH")));
    harvestSourceDTO.setEmails(rs.getString("EMAILS"));
    harvestSourceDTO.setTimeCreated(rs.getTimestamp("TIME_CREATED"));
    harvestSourceDTO.setStatements(new Integer(rs.getInt("STATEMENTS")));
    harvestSourceDTO.setCountUnavail(new Integer(rs.getInt("COUNT_UNAVAIL")));
    harvestSourceDTO.setLastHarvest(rs.getTimestamp("LAST_HARVEST"));
    harvestSourceDTO.setIntervalMinutes(rs.getInt("INTERVAL_MINUTES"));
    harvestSourceDTO.setOwner(rs.getString("SOURCE_OWNER"));
    harvestSourceDTO.setMediaType(rs.getString("MEDIA_TYPE"));

    String isPrioritySourceStr = rs.getString("PRIORITY_SOURCE");
    if (StringUtils.isNotBlank(isPrioritySourceStr)) {
        harvestSourceDTO.setPrioritySource(YesNoBoolean.parse(isPrioritySourceStr));
    }//from  ww w .  ja v a  2 s. c om

    String lastHarvestFailedStr = rs.getString("LAST_HARVEST_FAILED");
    if (StringUtils.isNotBlank(lastHarvestFailedStr)) {
        harvestSourceDTO.setLastHarvestFailed(YesNoBoolean.parse(lastHarvestFailedStr));
    }

    String isPermErrorStr = rs.getString("PERMANENT_ERROR");
    if (StringUtils.isNotBlank(isPermErrorStr)) {
        harvestSourceDTO.setPermanentError(YesNoBoolean.parse(isPermErrorStr));
    }

    String isSparqlEndpointStr = rs.getString("IS_SPARQL_ENDPOINT");
    if (StringUtils.isNotBlank(isSparqlEndpointStr)) {
        harvestSourceDTO.setSparqlEndpoint(YesNoBoolean.parse(isSparqlEndpointStr));
    }

    resultList.add(harvestSourceDTO);
}

From source file:com.ex.Dao.impl.GroupDaoImpl.java

@Override
public List<Group> listAllGroups() {
    String sql = "SELECT * FROM " + dbName + " ORDER BY GROUP_NAME";
    List<Group> groupsList = jdbcTemplate.query(sql, new RowMapper<Group>() {
        @Override//from w w w  .  ja  va2  s.  co  m
        public Group mapRow(ResultSet rs, int rowNum) throws SQLException {
            Group group = new Group();
            group.setId(rs.getString("group_id"));
            group.setVersion(rs.getLong("version"));
            group.setXml(rs.getString("xml"));
            group.setGroupName(rs.getString("GROUP_NAME"));
            group.setCreatedBy(rs.getString("created_by"));
            group.setUpdatedAt(rs.getTimestamp("updated_at"));
            return group;
        }
    });
    return groupsList;
}

From source file:com.linuxbox.enkive.audit.sqldb.SqlDbAuditService.java

private List<AuditEntry> createAuditEntries(ResultSet resultSet) throws SQLException {
    List<AuditEntry> results = new ArrayList<AuditEntry>();
    while (resultSet.next()) {
        try {/*from   w  w w  .  java  2 s.c  o m*/
            int id = resultSet.getInt(1);
            Date timestamp = resultSet.getTimestamp(2);
            int eventCode = resultSet.getInt(3);
            String username = resultSet.getString(4);
            String description = resultSet.getString(5);
            results.add(new AuditEntry(Integer.toString(id), timestamp, eventCode, username, description));
        } catch (SQLException e) {
            LOGGER.error("Could not return audit entry", e);
        }
    }
    return results;
}