Example usage for java.sql ResultSet getLong

List of usage examples for java.sql ResultSet getLong

Introduction

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

Prototype

long getLong(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

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

@Override
public License mapRow(ResultSet rs, int index) throws SQLException {
    License license = new License();

    license.setId(rs.getInt("id"));
    license.setMac(rs.getString("mac"));
    license.setUseTime(rs.getLong("use_time"));
    Timestamp ts = rs.getTimestamp("lastmod_time");
    if (ts != null)
        license.setLastModTime(new Date(ts.getTime()));
    license.setLastModUserid(rs.getInt("lastmod_userid"));

    return license;
}

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  ww w . j a  va2s . c  o 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.springsource.greenhouse.events.load.JdbcEventLoaderRepository.java

@Transactional
public int loadEventSession(EventSessionData sessionData) {
    try {/*www  .  j  a v a 2 s.c  o  m*/
        long[] sessionKey = jdbcTemplate.queryForObject(SELECT_EXTERNAL_SESSION, new RowMapper<long[]>() {
            public long[] mapRow(ResultSet rs, int rowNum) throws SQLException {
                return new long[] { rs.getLong("event"), rs.getInt("sessionId") };
            }
        }, sessionData.getSource(), sessionData.getSourceId());
        jdbcTemplate.update(UPDATE_SESSION, sessionData.getTitle(), sessionData.getDescription(),
                sessionData.getHashtag(), sessionData.getVenue(), sessionData.getTimeslot(), sessionKey[0],
                sessionKey[1]);
        logger.info("Updated session (EVENT = " + sessionKey[0] + ", ID = " + sessionKey[1] + ")");
        return 1;
    } catch (IncorrectResultSizeDataAccessException e) {
        // insert if it doesn't exist
        int newSessionId = jdbcTemplate.queryForInt("select max(id) from EventSession where event=?",
                sessionData.getEvent()) + 1;

        jdbcTemplate.update(INSERT_SESSION, sessionData.getEvent(), newSessionId, sessionData.getTitle(),
                sessionData.getDescription(), sessionData.getHashtag(), sessionData.getVenue(),
                sessionData.getTimeslot());
        jdbcTemplate.update(INSERT_EXTERNAL_SESSION, sessionData.getEvent(), newSessionId,
                sessionData.getSource(), sessionData.getSourceId(), new Date());

        List<Long> leaderIds = sessionData.getLeaderIds();
        int rank = 1;
        for (Long leaderId : leaderIds) {
            jdbcTemplate.update(INSERT_SESSION_LEADER, sessionData.getEvent(), newSessionId, leaderId, rank++);
        }

        logger.info("Created session (EVENT = " + sessionData.getEvent() + ", ID = " + newSessionId + ")");
        return newSessionId;
    }
}

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

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

    long subjectHash = rs.getLong("SUBJECT_HASH");
    boolean newSubject = currentSubject == null || subjectHash != currentSubject.getUriHash();
    if (newSubject) {
        currentSubject = new SubjectDTO(rs.getString("SUBJECT_URI"),
                YesNoBoolean.parse(rs.getString("ANON_SUBJ")));
        currentSubject.setUriHash(subjectHash);
        currentSubject.setLastModifiedDate(new Date(rs.getLong("SUBJECT_MODIFIED")));
        addNewSubject(subjectHash, currentSubject);
    }/*from w  w w .j  a v a 2s  .  c  o m*/

    String predicateUri = rs.getString("PREDICATE_URI");
    boolean newPredicate = newSubject || currentPredicate == null || !currentPredicate.equals(predicateUri);
    if (newPredicate) {
        currentPredicate = predicateUri;
        currentObjects = new ArrayList<ObjectDTO>();
        currentSubject.getPredicates().put(predicateUri, currentObjects);
    }

    ObjectDTO object = new ObjectDTO(rs.getString("OBJECT"), rs.getString("OBJ_LANG"),
            YesNoBoolean.parse(rs.getString("LIT_OBJ")), YesNoBoolean.parse(rs.getString("ANON_OBJ")));
    object.setHash(rs.getLong("OBJECT_HASH"));
    object.setSourceUri(rs.getString("SOURCE_URI"));
    object.setSourceHash(rs.getLong("SOURCE"));
    object.setDerivSourceUri(rs.getString("DERIV_SOURCE_URI"));
    object.setDerivSourceHash(rs.getLong("OBJ_DERIV_SOURCE"));
    object.setSourceObjectHash(rs.getLong("OBJ_SOURCE_OBJECT"));

    currentObjects.add(object);
}

From source file:org.jasig.schedassist.impl.reminder.PersistedReminderImplRowMapper.java

@Override
public PersistedReminderImpl mapRow(ResultSet rs, int rowNum) throws SQLException {
    PersistedReminderImpl result = new PersistedReminderImpl();
    result.setBlockEndTime(rs.getTimestamp("event_end"));
    result.setBlockStartTime(rs.getTimestamp("event_start"));
    result.setOwnerId(rs.getLong("owner_id"));
    result.setRecipientId(rs.getString("recipient"));
    result.setReminderId(rs.getLong("reminder_id"));
    result.setSendTime(rs.getTimestamp("send_time"));
    return result;
}

From source file:org.spirit.apps.jdbc.GenericRuntimeJDBCDao.java

/**
 * select first_name, surname from t_actor"
 * /*from  ww  w .j  a v a2 s.co  m*/
 * @param count_sql
 * @return
 */
public Collection jdbcQuerySystemFeedItems(final String sql) {
    if (this.jdbcTemplate == null) {
        return new ArrayList();
    }
    Collection feed_items = this.jdbcTemplate.query(sql, new RowMapper() {
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            SystemFeedItemsType feed_item = new SystemFeedItemsType();
            feed_item.setId(new Long(rs.getLong("id")));
            feed_item.setMainUrl(rs.getString("main_url"));
            return feed_item;
        }
    });
    return feed_items;
}

From source file:com.example.app.config.automation.demo.DemoDataConversionVersion1.java

/**
 * Example data conversion.//from   w ww  . jav  a  2  s  .  c  o  m
 *
 * @return data conversion.
 */
@Bean
@TaskQualifier(TaskQualifier.Type.data_conversion)
public DataConversion example2DataConversion() {
    final String[] signs = { "ARIES", "TAURUS", "GEMINI", "CANCER", "LEO", "VIRGO", "LIBRA", "SCORPIO",
            "SAGITTARIUS", "CAPRICORN", "AQUARIUS", "PISCES" };
    Arrays.sort(signs);

    final List<SQLStatement> preDDL = singletonList(
            new SQLStatement("CREATE TABLE Example_FOO(id serial, val text, primary key (id))", null));
    final List<SQLStatement> postDDL = singletonList(new SQLStatement("DROP TABLE Example_FOO;", null));
    return new AbstractDataConversion(IDENTIFIER, "Example Numero Dos", 2, true, null, preDDL, postDDL) {
        @Override
        @Nonnull
        public List<TaskArgument> getAdditionalArguments() {
            List<TaskArgument> args = new ArrayList<>();
            args.add(new TaskArgument(WHAT_S_YOUR_ZODIAC_SIGN, "", "Cancer", null));
            return args;
        }

        @Override
        public List<? extends SQLStatement> execute(TaskArgument... arguments)
                throws SQLException, IllegalArgumentException {
            final SQLStatement stmt = new SQLStatement("INSERT INTO Example_Foo (val) VALUES (?)",
                    "Insert Sign");
            final Map<String, TaskArgument> argumentMapping = getArgumentMapping(arguments);
            stmt.setString(1, argumentMapping.get(WHAT_S_YOUR_ZODIAC_SIGN).getArgument().toString());
            return singletonList(stmt);
        }

        @NotNull
        @Override
        public Map<TaskArgument, String> validateArguments(TaskArgument... arguments) {
            final Map<TaskArgument, String> validationMap = new HashMap<>();
            final String sign = arguments[0].getArgument().toString().toUpperCase();
            final int foundIndex = Arrays.binarySearch(signs, sign);
            if (foundIndex < 0)
                validationMap.put(arguments[0], "That's not your sign fool.");
            return validationMap;
        }

        @Override
        public List<? extends SQLStatement> getValidationStatements() {
            return singletonList(new SQLStatement("SELECT COUNT(*) FROM Example_FOO", null));
        }

        @Override
        public String validateResult(SQLStatement stmt, int index, ResultSet result) throws SQLException {
            if (result.next()) {
                long count = result.getLong(1);
                return count == 1 ? null : "Received incorrect record count: " + count;
            } else
                return "Expecting Results";
        }
    };
}

From source file:com.grayfox.server.dao.jdbc.UserJdbcDao.java

@Override
public List<User> findCompactFriendsByFoursquareId(String foursquareId) {
    return getJdbcTemplate().query(getQuery("User.findFriendsByUserFoursquareId"), (ResultSet rs, int i) -> {
        User user = new User();
        int columnIndex = 1;
        user.setId(rs.getLong(columnIndex++));
        user.setName(rs.getString(columnIndex++));
        user.setLastName(rs.getString(columnIndex++));
        user.setPhotoUrl(rs.getString(columnIndex++));
        user.setFoursquareId(rs.getString(columnIndex++));
        return user;
    }, foursquareId);//  ww w.  ja  v  a 2 s  .co  m
}

From source file:jobimtext.thesaurus.distributional.DatabaseThesaurusDatastructure.java

public Long getValuesCount(String key) {
    Long count = 0L;/*from w  ww  . j a  v a 2s .  com*/
    String sql = "SELECT count FROM " + tableValues + " WHERE feature = ?";
    PreparedStatement ps;
    try {
        ps = getDatabaseConnection().getConnection().prepareStatement(sql);
        ps.setString(1, key);
        ResultSet set = ps.executeQuery();
        if (set.next()) {
            count = set.getLong("count");
        }
        ps.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return count;
}

From source file:com.napkindrawing.dbversion.InstalledRevision.java

public InstalledRevision(ResultSet rs) {
    super();//from   w w w.  j  a  v a 2 s.c om
    try {
        setProfileName(rs.getString("profile"));
        setVersion(new Version(rs.getString("version")));
        setUpgradeDate(rs.getLong("upgrade_date"));
        setName(rs.getString("upgrade_script_name"));
        setUpgradeScriptCompiled(rs.getString("upgrade_script_compiled"));
        setUpgradeScriptCompiledChecksum(rs.getString("upgrade_script_compiled_checksum"));
        setUpgradeScriptData(rs.getString("upgrade_script_data"));
        setUpgradeScriptTemplate(rs.getString("upgrade_script_template"));
        setUpgradeScriptTemplateChecksum(rs.getString("upgrade_script_template_checksum"));
        setPostUpgradeSchemaDump(rs.getString("post_upgrade_schema_dump"));
        setPostUpgradeSchemaDumpChecksum(rs.getString("post_upgrade_schema_dump_checksum"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}