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:org.envirocar.aggregation.AggregatedTracksServlet.java

private String createAggregatedTracksList() throws SQLException {
    ResultSet rs = this.connection.executeQueryStatement(query);

    ArrayNode array = om.createArrayNode();
    ObjectNode object;/*  w w  w .jav a  2 s .c  o m*/
    String id;
    Timestamp ts;
    while (rs.next()) {
        object = om.createObjectNode();
        id = rs.getString("id");
        ts = rs.getTimestamp(AGGREGATION_DATE);

        object.put(id, df.format(new Date(ts.getTime())));

        array.add(object);
    }

    rs.close();

    ObjectNode node = om.createObjectNode();

    node.put("tracks", array);
    return node.toString();
}

From source file:org.apache.niolex.config.dao.impl.ConfigItemRowMapper.java

/**
 * Override super method/*w  ww. j  a  v a 2  s  . c om*/
 * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
 */
@Override
public ConfigItem mapRow(ResultSet rs, int rowNum) throws SQLException {
    // groupid, ckey, value, curid, uurid, updatetime
    ConfigItem config = new ConfigItem();
    config.setGroupId(rs.getInt("groupid"));
    config.setcUid(rs.getInt("curid"));
    config.setuUid(rs.getInt("uurid"));
    config.setKey(rs.getString("ckey"));
    config.setValue(rs.getString("value"));
    config.setUpdateTime(rs.getTimestamp("updatetime").getTime());
    return config;
}

From source file:net.sourceforge.vulcan.spring.jdbc.ChangeSetQuery.java

@Override
protected ChangeSetDto mapRow(ResultSet rs, int rowNumber) throws SQLException {
    final ChangeSetDto dto = new ChangeSetDto();

    dto.setMessage(rs.getString("message"));
    dto.setAuthorName(rs.getString("author"));
    dto.setAuthorEmail(rs.getString("author_email"));
    dto.setRevisionLabel(rs.getString("revision_label"));

    final Timestamp timestamp = rs.getTimestamp("commit_timestamp");

    if (!rs.wasNull()) {
        dto.setTimestamp(new Date(timestamp.getTime()));
    }/*ww  w  . ja v a  2  s  .  c  o  m*/

    int buildId = rs.getInt("build_id");
    int changeSetId = rs.getInt("change_set_id");

    final List<ModifiedPathDto> paths = modifiedPathQuery.queryModifiedPaths(buildId, changeSetId);
    dto.setModifiedPaths(paths);

    return dto;
}

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

public Map<String, String> transfer(ResultSet resultSet, ViewMode viewMode) {
    Map<String, String> message = new HashMap<>();
    try {/*  w w w  .j  a v a  2  s  .  c om*/
        message.put("id", resultSet.getString("id"));
        message.put("message", resultSet.getString("message"));
        message.put("create_date",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(resultSet.getTimestamp("create_date")));
        String username = resultSet.getString("username");
        if (!StringUtils.isEmpty(username)) {
            message.put("commenter", username);
        } else {
            message.put("commenter", resultSet.getString("city") + "?");
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    return message;
}

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

public Map<String, String> transfer(ResultSet resultSet, ViewMode viewMode) {
    Map<String, String> record = new HashMap<>();
    try {/*w w w .  ja v a 2s . c o  m*/
        record.put("id", resultSet.getString("id"));
        record.put("create_date",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(resultSet.getTimestamp("create_date")));
        record.put("title", resultSet.getString("title"));
        record.put("record", resultSet.getString("record"));
        record.put("escapeHtml", StringUtil.escapeHtml(record.get("record")));
        String content = resultSet.getString("content");
        record.put("content", content);
        record.put("summary", StringUtil.substring(content, 100));
        record.put("username", resultSet.getString("username"));
        record.put("access_times", resultSet.getString("access_times"));
        record.put("good_times", resultSet.getString("good_times"));
        if (ViewMode.DYNAMIC == viewMode) {
            record.put("url", RecordHelper.generateDynamicPath(Integer.valueOf(record.get("id"))));
        } else {
            record.put("url", RecordHelper.generateStaticPath(Integer.valueOf(record.get("id"))));
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    return record;
}

From source file:net.solarnetwork.node.dao.jdbc.general.JdbcGeneralNodeDatumDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public List<GeneralNodeDatum> getDatumNotUploaded(String destination) {
    return findDatumNotUploaded(new RowMapper<GeneralNodeDatum>() {

        @Override//w  w  w. j a  va  2s. c  o  m
        public GeneralNodeDatum mapRow(ResultSet rs, int rowNum) throws SQLException {
            if (log.isTraceEnabled()) {
                log.trace("Handling result row " + rowNum);
            }
            GeneralNodeDatum datum = new GeneralNodeDatum();
            int col = 0;
            datum.setCreated(rs.getTimestamp(++col));
            datum.setSourceId(rs.getString(++col));

            String jdata = rs.getString(++col);
            if (jdata != null) {
                GeneralNodeDatumSamples s;
                try {
                    s = objectMapper.readValue(jdata, GeneralNodeDatumSamples.class);
                    datum.setSamples(s);
                } catch (IOException e) {
                    log.error("Error deserializing JSON into GeneralNodeDatumSamples: {}", e.getMessage());
                }
            }
            return datum;
        }
    });
}

From source file:org.copperengine.spring.audit.AuditTrailQueryEngine.java

@Override
public List<AuditTrailInfo> getAuditTrails(String transactionId, String conversationId, String correlationId,
        Integer level, int maxResult) {

    SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();

    String sortClause = "SEQ_ID";
    String whereClause = "where 1=1 ";
    List<Object> args = new ArrayList<Object>();

    if (level != null) {
        whereClause += " and LOGLEVEL <= ? ";
        sortClause = "LOGLEVEL";
        args.add(level);//from w ww  .ja v  a2 s  . c  o  m
    }
    if (StringUtils.hasText(correlationId)) {
        whereClause += " and CORRELATION_ID = ? ";
        sortClause = "CORRELATION_ID";
        args.add(correlationId);
    }

    if (StringUtils.hasText(conversationId)) {
        whereClause += " and CONVERSATION_ID = ? ";
        sortClause = "CONVERSATION_ID";
        args.add(conversationId);
    }

    if (StringUtils.hasText(transactionId)) {
        whereClause += " and TRANSACTION_ID = ? ";
        sortClause = "TRANSACTION_ID";
        args.add(transactionId);
    }

    String selectClause = "select " + "SEQ_ID," + "TRANSACTION_ID," + "CONVERSATION_ID," + "CORRELATION_ID,"
            + "OCCURRENCE," + "LOGLEVEL," + "CONTEXT," + "INSTANCE_ID," + "MESSAGE_TYPE";

    factory.setDataSource(getDataSource());
    factory.setFromClause("from COP_AUDIT_TRAIL_EVENT ");

    factory.setSelectClause(selectClause);

    factory.setWhereClause(whereClause);
    factory.setSortKey(sortClause);

    PagingQueryProvider queryProvider = null;
    try {
        queryProvider = (PagingQueryProvider) factory.getObject();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }

    String query = queryProvider.generateFirstPageQuery(maxResult);

    // this.getJdbcTemplate().setQueryTimeout(1000);

    long start = System.currentTimeMillis();
    RowMapper<AuditTrailInfo> rowMapper = new RowMapper<AuditTrailInfo>() {

        public AuditTrailInfo mapRow(ResultSet rs, int arg1) throws SQLException {

            return new AuditTrailInfo(rs.getLong("SEQ_ID"), rs.getString("TRANSACTION_ID"),
                    rs.getString("CONVERSATION_ID"), rs.getString("CORRELATION_ID"),
                    rs.getTimestamp("OCCURRENCE").getTime(), rs.getInt("LOGLEVEL"), rs.getString("CONTEXT"),
                    rs.getString("INSTANCE_ID"), rs.getString("MESSAGE_TYPE"));
        }

    };
    List<AuditTrailInfo> res = this.getJdbcTemplate().query(query, rowMapper, args.toArray());

    long end = System.currentTimeMillis();

    logger.info("query took: " + (end - start) + " ms : " + query);

    return res;
}

From source file:com.ewcms.component.comment.dao.CommentDAO.java

private List<Reply> findReply(final Long commentId) {
    String sql = "Select * From component_comment_reply Where comment_id = ?";
    Object[] params = { commentId };
    return jdbcTemplate.query(sql, params, new RowMapper<Reply>() {

        @Override//ww  w  .  ja  va  2 s.  c o  m
        public Reply mapRow(ResultSet rs, int rowNum) throws SQLException {
            Reply reply = new Reply();
            reply.setId(rs.getLong("id"));
            reply.setCommentId(commentId);
            reply.setIp(rs.getString("ip"));
            reply.setUsername(rs.getString("username"));
            reply.setDate(rs.getTimestamp("date"));
            return reply;
        }
    });
}

From source file:ru.org.linux.spring.dao.DeleteInfoDao.java

/**
 * ,     ?//from  ww w. java 2s  .c  o m
 * @param id id ? ??
 * @param forUpdate  ?     (SELECT ... FOR UPDATE)
 * @return ?   ?
 */
public DeleteInfo getDeleteInfo(int id, boolean forUpdate) {
    List<DeleteInfo> list = jdbcTemplate.query(forUpdate ? QUERY_DELETE_INFO_FOR_UPDATE : QUERY_DELETE_INFO,
            new RowMapper<DeleteInfo>() {
                @Override
                public DeleteInfo mapRow(ResultSet resultSet, int i) throws SQLException {
                    Integer bonus = resultSet.getInt("bonus");
                    if (resultSet.wasNull()) {
                        bonus = null;
                    }

                    return new DeleteInfo(resultSet.getInt("userid"), resultSet.getString("reason"),
                            resultSet.getTimestamp("deldate"), bonus);
                }
            }, id);

    if (list.isEmpty()) {
        return null;
    } else {
        return list.get(0);
    }
}

From source file:net.solarnetwork.node.dao.jdbc.consumption.JdbcConsumptionDatumDao.java

@Override
@Transactional(readOnly = true, propagation = Propagation.REQUIRED)
public List<ConsumptionDatum> getDatumNotUploaded(String destination) {
    return findDatumNotUploaded(new RowMapper<ConsumptionDatum>() {

        @Override//  w  w w. j a  v  a 2s  .  c  o  m
        public ConsumptionDatum mapRow(ResultSet rs, int rowNum) throws SQLException {
            if (log.isTraceEnabled()) {
                log.trace("Handling result row " + rowNum);
            }
            ConsumptionDatum datum = new ConsumptionDatum();
            int col = 1;
            datum.setCreated(rs.getTimestamp(col++));
            datum.setSourceId(rs.getString(col++));

            Number val = (Number) rs.getObject(col++);
            datum.setLocationId(val == null ? null : val.longValue());

            val = (Number) rs.getObject(col++);
            datum.setWatts(val == null ? null : val.intValue());

            val = (Number) rs.getObject(col++);
            datum.setWattHourReading(val == null ? null : val.longValue());

            return datum;
        }
    });
}