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:edu.umass.cs.gnsclient.client.util.keystorage.SimpleKeyStore.java

/**
 *
 * @param key//from  ww w  .  ja  v  a2 s  . c  om
 * @return the update time as a Date
 */
public Date updateTime(String key) {
    ResultSet rs = null;
    try {
        PreparedStatement getStatement = conn
                .prepareStatement("select UPDATETIME from " + TABLE_NAME + " where KEYFIELD=?");
        getStatement.setString(1, key);
        rs = getStatement.executeQuery();
        if (rs.next()) {
            return rs.getTimestamp("UPDATETIME");
        }
    } catch (SQLException e) {
        DerbyControl.printSQLException(e);
    } finally {
        safelyClose(rs);
    }
    return null;
}

From source file:gda.jython.scriptcontroller.logging.LoggingScriptController.java

private ScriptControllerLogResults refreshExistingEntry(ScriptControllerLoggingMessage arg)
        throws SQLException {
    String[] valuesToAdd = getUpdateValues(arg);
    int i = 1;//from   www .j  a v  a2s. c o m
    for (; i <= valuesToAdd.length; i++) {
        psRefresh.setString(i, valuesToAdd[i - 1]);
    }
    Timestamp now = new Timestamp(System.currentTimeMillis());
    psRefresh.setTimestamp(i++, now);
    psRefresh.setString(i++, arg.getUniqueID());
    int numLinesUpdated = psRefresh.executeUpdate();
    if (numLinesUpdated != 1) {
        System.out.println("something's wrong");
        return null;
    }

    psFetchStartTime.setString(1, arg.getUniqueID());
    ResultSet rsStartTime = psFetchStartTime.executeQuery();
    rsStartTime.next();
    Timestamp startTime = rsStartTime.getTimestamp(1);

    return new ScriptControllerLogResults(arg.getUniqueID(), arg.getName(), startTime, now);
}

From source file:org.jasig.schedassist.impl.statistics.AppointmentEventRowMapper.java

/**
 * Expects the following columns in the {@link ResultSet}:
 * //from   w ww . j a  v a2  s.com
 <pre>
  event_id
  owner_id
  visitor_id,
  event_type,
  event_timestamp,
  event_start 
 </pre>
 * 
 * @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
 */
@Override
public AppointmentEvent mapRow(ResultSet rs, int rowNum) throws SQLException {
    AppointmentEvent event = new AppointmentEvent();

    event.setEventId(rs.getLong("EVENT_ID"));
    final long ownerId = rs.getLong("OWNER_ID");
    event.setOwnerId(ownerId);
    IScheduleOwner owner = ownerDao.locateOwnerByAvailableId(ownerId);
    event.setScheduleOwner(owner);

    final String visitorId = rs.getString("VISITOR_ID");
    event.setVisitorId(visitorId);

    event.setEventType(EventType.valueOf(rs.getString("EVENT_TYPE")));
    event.setEventTimestamp(rs.getTimestamp("EVENT_TIMESTAMP"));
    event.setAppointmentStartTime(rs.getTimestamp("EVENT_START"));

    return event;
}

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

@Override
public List<Cacl> getFormList(String uid) {
    String sql = "select * from cacl where cid in (select cid from uc where uid = " + uid + ")";
    System.out.println(sql);//from  w w w.j  av  a 2 s  .co  m

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

    }

    SqlDB.close();

    return list;
}

From source file:com.chaosinmotion.securechat.server.commands.GetMessages.java

public static ReturnResult processRequest(Login.UserInfo userinfo, JSONObject requestParams)
        throws ClassNotFoundException, SQLException, IOException {
    String deviceid = requestParams.optString("deviceid");
    MessageReturnResult mrr = new MessageReturnResult();

    /*//from   www .  j ava  2 s  . c  o m
     * Save message to the database.
     */

    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        /*
         * Get the device ID for this device. Verify it belongs to the
         * user specified
         */
        c = Database.get();
        ps = c.prepareStatement("SELECT deviceid " + "FROM Devices " + "WHERE deviceuuid = ? AND userid = ?");
        ps.setString(1, deviceid);
        ps.setInt(2, userinfo.getUserID());
        rs = ps.executeQuery();

        int deviceID = 0;
        if (rs.next()) {
            deviceID = rs.getInt(1);
        }

        rs.close();
        ps.close();
        if (deviceID == 0) {
            return new ReturnResult(Errors.ERROR_UNKNOWNDEVICE, "Unknown device");
        }

        /*
         * Run query to get messages
         */

        ps = c.prepareStatement("SELECT Messages.messageid, " + "    Messages.senderid, "
                + "    Users.username, " + "    Messages.toflag, " + "    Messages.received, "
                + "    Messages.message " + "FROM Messages, Users " + "WHERE Messages.deviceid = ? "
                + "  AND Messages.senderid = Users.userid");
        ps.setInt(1, deviceID);

        rs = ps.executeQuery();
        while (rs.next()) {
            int messageID = rs.getInt(1);
            int senderID = rs.getInt(2);
            String senderName = rs.getString(3);
            boolean toflag = rs.getBoolean(4);
            Timestamp received = rs.getTimestamp(5);
            byte[] message = rs.getBytes(6);

            mrr.addMessage(messageID, senderID, senderName, toflag, received, message);
        }

        /*
         * Return messages
         */
        return mrr;
    } finally {
        if (rs != null)
            rs.close();
        if (ps != null)
            ps.close();
        if (c != null)
            c.close();
    }
}

From source file:com.concursive.connect.web.modules.discussion.dao.TopicIndexer.java

/**
 * Given a database and a Lucene writer, this method will add content to the
 * searchable index/*from www .ja v a  2s .  co m*/
 *
 * @param writer  Description of the Parameter
 * @param db      Description of the Parameter
 * @param context
 * @throws SQLException Description of the Exception
 * @throws IOException  Description of the Exception
 */
public void add(IIndexerService writer, Connection db, IndexerContext context)
        throws SQLException, IOException {
    int count = 0;
    PreparedStatement pst = db
            .prepareStatement("SELECT issue_id, project_id, category_id, subject, message, modified "
                    + "FROM project_issues " + "WHERE project_id > -1 ");
    ResultSet rs = pst.executeQuery();
    while (rs.next() && context.getEnabled()) {
        ++count;
        // read the record
        Topic topic = new Topic();
        topic.setId(rs.getInt("issue_id"));
        topic.setProjectId(rs.getInt("project_id"));
        topic.setCategoryId(rs.getInt("category_id"));
        topic.setSubject(rs.getString("subject"));
        topic.setBody(rs.getString("message"));
        topic.setModified(rs.getTimestamp("modified"));
        // add the document
        writer.indexAddItem(topic, false);
    }
    rs.close();
    pst.close();
    LOG.info("IssueIndexer Finished: " + count);
}

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()));
    }//from  w  ww  . j  a v a  2 s. c  om

    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:org.chimi.s4s.metainfo.mysql.MysqlMetaInfoDaoTest.java

private void assertData(String id, FileMetadata metadata) throws Throwable {
    Connection conn = dataSource.getConnection();
    PreparedStatement pstmt = conn.prepareStatement("select * from FILE_METADATA where FILE_METADATA_ID = ?");
    int idValue = Integer.parseInt(id);
    pstmt.setInt(1, idValue);//w w w.  j  ava 2  s .  co  m
    ResultSet rs = pstmt.executeQuery();

    assertTrue(rs.next());
    assertEquals(idValue, rs.getInt("FILE_METADATA_ID"));
    assertEquals(metadata.getServiceId(), rs.getString("SERVICE_ID"));
    assertEquals(metadata.getFileName(), rs.getString("FILE_NAME"));
    assertEquals(metadata.getLength(), rs.getLong("FILE_LENGTH"));
    assertEquals(metadata.getMimetype(), rs.getString("MIMETYPE"));
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    assertEquals(format.format(metadata.getUploadTime()), format.format(rs.getTimestamp("UPLOAD_TIME")));
    assertEquals(metadata.getFileId(), rs.getString("FILE_ID"));

    rs.close();
    pstmt.close();
    conn.close();
}

From source file:com.concursive.connect.web.modules.plans.dao.AssignmentNoteIndexer.java

/**
 * Given a database and a Lucene writer, this method will add content to the
 * searchable index/*from w w  w  .  ja  va  2s. co m*/
 *
 * @param writer  Description of the Parameter
 * @param db      Description of the Parameter
 * @param context
 * @throws SQLException Description of the Exception
 * @throws IOException  Description of the Exception
 */
public void add(IIndexerService writer, Connection db, IndexerContext context)
        throws SQLException, IOException {
    int count = 0;
    PreparedStatement pst = db
            .prepareStatement("SELECT s.status_id, s.assignment_id, s.user_id, s.description, s.status_date, "
                    + "a.project_id " + "FROM project_assignments_status s "
                    + "LEFT JOIN project_assignments a ON s.assignment_id = a.assignment_id "
                    + "WHERE s.status_id > -1 ");
    ResultSet rs = pst.executeQuery();
    while (rs.next() && context.getEnabled()) {
        ++count;
        // read the record
        AssignmentNote assignmentNote = new AssignmentNote();
        assignmentNote.setId(rs.getInt("status_id"));
        assignmentNote.setAssignmentId(rs.getInt("assignment_id"));
        assignmentNote.setUserId(rs.getInt("user_id"));
        assignmentNote.setDescription(rs.getString("description"));
        assignmentNote.setEntered(rs.getTimestamp("status_date"));
        assignmentNote.setProjectId(rs.getInt("project_id"));
        // add the document
        writer.indexAddItem(assignmentNote);
    }
    rs.close();
    pst.close();
    LOG.info("AssignmentNoteIndexer-> Finished: " + count);
}

From source file:org.surfnet.cruncher.repository.StatisticsRepositoryImpl.java

@Override
public List<LoginEntry> getUnprocessedLoginEntries(int nrOfRecords) {
    Long aggregateStartingPoint = cruncherJdbcTemplate
            .queryForLong("select aggregatepoint from aggregate_meta_data");

    NamedParameterJdbcTemplate namedJdbcTemplate = new NamedParameterJdbcTemplate(ebJdbcTemplate);

    String query = "select * from log_logins where id > :startingPoint order by id LIMIT :batchSize";

    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("batchSize", nrOfRecords);
    parameterMap.put("startingPoint", aggregateStartingPoint);

    return namedJdbcTemplate.query(query, parameterMap, new RowMapper<LoginEntry>() {
        @Override/*from w  ww .jav a2  s. c  o m*/
        public LoginEntry mapRow(ResultSet rs, int rowNum) throws SQLException {
            Long id = rs.getLong("id");
            String idpEntityId = rs.getString("idpentityid");
            String idpEntityName = rs.getString("idpentityname");
            Date loginDate = new Date(rs.getTimestamp("loginstamp").getTime());
            String spEntityId = rs.getString("spentityid");
            String spEntityName = rs.getString("spentityname");
            String userId = rs.getString("userid");
            return new LoginEntry(id, idpEntityId, idpEntityName, loginDate, spEntityId, spEntityName, userId);
        }
    });
}