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:dsd.dao.RawDataDAO.java

public static ArrayList<RawData> GetAllForPeriod(Calendar startDate, Calendar endDate) {
    try {//from  ww  w . java 2  s  .c o  m
        Connection con = DAOProvider.getDataSource().getConnection();
        ArrayList<RawData> rawDataList = new ArrayList<RawData>();
        try {
            Object[] parameters = new Object[2];
            parameters[0] = new Timestamp(startDate.getTimeInMillis());
            parameters[1] = new Timestamp(endDate.getTimeInMillis());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, "*",
                    " timestamp >= ? and timestamp <= ? ", "", con, parameters);
            while (results.next()) {
                RawData dataTuple = new RawData();
                dataTuple.setRawDataID(results.getInt("ID"));
                dataTuple.setWindSpeed(results.getFloat(fields[0]));
                dataTuple.setWindDirection(results.getFloat(fields[1]));
                dataTuple.setHydrometer(results.getFloat(fields[2]));
                dataTuple.setSonar(results.getFloat(fields[3]));
                dataTuple.setSonarType(eSonarType.getSonarType(results.getInt(fields[4])));
                dataTuple.setTimestamp(results.getTimestamp(fields[5]).getTime());
                rawDataList.add(dataTuple);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
        return rawDataList;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return null;

}

From source file:jongo.handler.JongoResultSetHandler.java

/**
 * Converts a ResultSet to a Map. Important to note that DATE, TIMESTAMP & TIME objects generate
 * a {@linkplain org.joda.time.DateTime} object using {@linkplain org.joda.time.format.ISODateTimeFormat}.
 * @param resultSet a {@linkplain java.sql.ResultSet}
 * @return a Map with the column names as keys and the values. null if something goes wrong.
 *//*  w  ww  .j a v  a2  s  .  c  o m*/
public static Map<String, String> resultSetToMap(ResultSet resultSet) {
    Map<String, String> map = new HashMap<String, String>();
    try {
        int columnCount = resultSet.getMetaData().getColumnCount();

        l.trace("Mapping a result set with " + columnCount + " columns to a Map");

        ResultSetMetaData meta = resultSet.getMetaData();
        for (int i = 1; i < columnCount + 1; i++) {
            String colName = meta.getColumnName(i).toLowerCase();
            int colType = meta.getColumnType(i);
            String v = resultSet.getString(i);
            if (colType == Types.DATE) {
                v = new DateTime(resultSet.getDate(i)).toString(dateFTR);
                l.trace("Mapped DATE column " + colName + " with value : " + v);
            } else if (colType == Types.TIMESTAMP) {
                v = new DateTime(resultSet.getTimestamp(i)).toString(dateTimeFTR);
                l.trace("Mapped TIMESTAMP column " + colName + " with value : " + v);
            } else if (colType == Types.TIME) {
                v = new DateTime(resultSet.getTimestamp(i)).toString(timeFTR);
                l.trace("Mapped TIME column " + colName + " with value : " + v);
            } else {
                l.trace("Mapped " + meta.getColumnTypeName(i) + " column " + colName + " with value : " + v);
            }
            map.put(colName, v);
        }
    } catch (SQLException e) {
        l.error("Failed to map ResultSet");
        l.error(e.getMessage());
        return null;
    }

    return map;
}

From source file:at.alladin.rmbt.db.fields.TimestampField.java

@Override
public void setField(final ResultSet rs) throws SQLException {
    value = rs.getTimestamp(dbKey);
}

From source file:ch.digitalfondue.npjt.mapper.InstantMapper.java

@Override
public Object getObject(ResultSet rs) throws SQLException {
    return toInstant(rs.getTimestamp(name));
}

From source file:ru.mystamps.web.dao.impl.SitemapInfoDtoRowMapper.java

@Override
public SitemapInfoDto mapRow(ResultSet resultSet, int i) throws SQLException {
    Integer id = resultSet.getInt("id");
    Date updatedAt = resultSet.getTimestamp("updated_at");

    return new SitemapInfoDto(id, updatedAt);
}

From source file:ch.digitalfondue.npjt.mapper.LocalDateTimeMapper.java

@Override
public Object getObject(ResultSet rs) throws SQLException {
    return toLocalDateTime(rs.getTimestamp(name));
}

From source file:org.zenoss.zep.dao.impl.compat.DatabaseCompatibilityPostgreSQL.java

@Override
public TypeConverter<Long> getTimestampConverter() {
    return new TypeConverter<Long>() {
        @Override//from w ww  .  j  a v  a  2s.c  o m
        public Long fromDatabaseType(ResultSet rs, String columnName) throws SQLException {
            Timestamp ts = rs.getTimestamp(columnName);
            return (ts != null) ? ts.getTime() : null;
        }

        @Override
        public Object toDatabaseType(Long timestampInMillis) {
            if (timestampInMillis == null) {
                return null;
            }
            return new Timestamp(timestampInMillis);
        }
    };
}

From source file:com.emc.ecs.sync.service.MySQLDbService.java

@Override
protected Date getResultDate(ResultSet rs, String name) throws SQLException {
    return new Date(rs.getTimestamp(name).getTime());
}

From source file:com.keybox.manage.db.PublicKeyDB.java

/**
 * returns public key base on id//w w w  .  j  a  v  a2  s.c  o m
 *
 * @param con         DB connection
 * @param publicKeyId key id
 * @return script object
 */
public static PublicKey getPublicKey(Connection con, Long publicKeyId) {

    PublicKey publicKey = null;
    try {
        PreparedStatement stmt = con.prepareStatement("select * from  public_keys where id=?");
        stmt.setLong(1, publicKeyId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            publicKey = new PublicKey();
            publicKey.setId(rs.getLong("id"));
            publicKey.setKeyNm(rs.getString(KEY_NM));
            publicKey.setPublicKey(rs.getString(PUBLIC_KEY));
            publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID)));
            publicKey.setType(rs.getString("type"));
            publicKey.setFingerprint(rs.getString("fingerprint"));
            publicKey.setCreateDt(rs.getTimestamp(CREATE_DT));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }

    return publicKey;
}

From source file:com.tethrnet.manage.db.PublicKeyDB.java

/**
 * returns public key base on id/*from   w ww  .j  a  va 2s .com*/
 *
 * @param con         DB connection
 * @param publicKeyId key id
 * @return script object
 */
public static PublicKey getPublicKey(Connection con, Long publicKeyId) {

    PublicKey publicKey = null;
    try {
        PreparedStatement stmt = con.prepareStatement("select * from  public_keys where id=?");
        stmt.setLong(1, publicKeyId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            publicKey = new PublicKey();
            publicKey.setId(rs.getLong("id"));
            publicKey.setKeyNm(rs.getString("key_nm"));
            publicKey.setPublicKey(rs.getString("public_key"));
            publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id")));
            publicKey.setType(rs.getString("type"));
            publicKey.setFingerprint(rs.getString("fingerprint"));
            publicKey.setCreateDt(rs.getTimestamp("create_dt"));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }

    return publicKey;
}