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:org.ohmage.query.impl.AnnotationQueries.java

@Override
public List<Annotation> readPromptResponseAnnotations(final UUID surveyId, final String promptId,
        final String repeatableSetId, final Integer repeatableSetIteration) throws DataAccessException {

    StringBuilder sql = new StringBuilder(SQL_READ_PROMPT_RESPONSE_ANNOTATION);
    List<Object> args = new ArrayList<Object>();
    args.add(surveyId.toString());// w  w  w .  j a  v  a2 s.c  o  m
    args.add(promptId);

    if (repeatableSetId != null && repeatableSetIteration != null) {
        sql.append(SQL_READ_PROMPT_RESPONSE_ANNOTATION_AND_REPEATABLE_SET);
        args.add(repeatableSetId);
        args.add(repeatableSetIteration);
    }

    try {
        return getJdbcTemplate().query(sql.toString(), args.toArray(), new RowMapper<Annotation>() {
            public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException {
                try {
                    return new Annotation(rs.getString(1), rs.getString(2), rs.getLong(3), rs.getString(4));
                } catch (DomainException e) {
                    throw new SQLException("Error creating an annotation object.", e);
                }
            }
        });
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("An error occurred when running the following SQL: '" + sql.toString()
                + " with the parameters " + args, e);
    }
}

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//  w w w . ja  v  a  2 s.co 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);
        }
    });
}

From source file:com.migratebird.database.impl.DefaultSQLHandler.java

public long getItemAsLong(String sql, DataSource dataSource) {
    logger.debug(sql);//from  ww w  . j a va 2  s. c  o m

    Statement statement = null;
    ResultSet resultSet = null;
    try {
        statement = getConnection(dataSource).createStatement();
        resultSet = statement.executeQuery(sql);
        if (resultSet.next()) {
            return resultSet.getLong(1);
        }
    } catch (Exception e) {
        throw new DatabaseException("Error while executing statement: " + sql, e);
    } finally {
        closeQuietly(null, statement, resultSet);
    }

    // in case no value was found, throw an exception
    throw new DatabaseException("No item value found: " + sql);
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public Schedule getScheduleByWeek(long parentId, int week) {
    return jdbcTemplate.execute((Statement statement) -> {
        ResultSet rs = statement.executeQuery("SELECT * FROM schedule WHERE parent_id = " + parentId
                + " AND week = " + week + " ORDER BY activity_date");
        Schedule schedule = null;// w  w  w. jav  a2  s.c  om
        if (rs.next()) {
            schedule = new Schedule();
            schedule.setActivityDate(rs.getDate("activity_date").toLocalDate());
            schedule.setParentId(rs.getLong("parent_id"));
            schedule.setWeek(rs.getInt("week"));
        }
        return schedule;
    });
}

From source file:data.DefaultExchanger.java

protected void putLong(JsonGenerator generator, String fieldName, ResultSet rs, short index)
        throws SQLException, IOException {
    generator.writeFieldName(fieldName);
    long value = rs.getLong(index);
    if (rs.wasNull()) {
        generator.writeNull();//from   ww w.  ja  va 2 s .  c  o  m
    } else {
        generator.writeNumber(value);
    }
}

From source file:me.redstarstar.rdfx.duty.dao.jdbc.ScheduleJdbcDao.java

@Override
public List<Schedule> listSchedulesByWeek(int week) {
    return jdbcTemplate.execute((Statement statement) -> {
        ResultSet rs = statement
                .executeQuery("SELECT * FROM schedule WHERE week = " + week + " ORDER BY activity_date");
        List<Schedule> schedules = new ArrayList<>();
        while (rs.next()) {
            Schedule schedule = new Schedule();
            schedule.setActivityDate(rs.getDate("activity_date").toLocalDate());
            schedule.setParentId(rs.getLong("parent_id"));
            schedule.setWeek(rs.getInt("week"));
            schedules.add(schedule);//from  ww w  . j  a  v a  2  s . c o  m
        }
        return schedules;
    });
}

From source file:me.ronghai.sa.dao.impl.AbstractModelDAOWithJDBCImpl.java

public List<Object> findRelatedIDs(final String relationTable, final String returnColumn,
        final String whereColumn, final Long productId) {
    String sql = " SELECT " + returnColumn + " FROM `" + relationTable + "`  WHERE " + whereColumn + " = ? ";
    List<Object> ids = this.databaseHandler.query(sql, new Object[] { productId }, new RowMapper<Object>() {
        @Override//from ww  w. j  a v  a  2  s  .com
        public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
            return arg0.getLong(returnColumn);
        }
    });

    return ids;
}

From source file:org.ohmage.query.impl.AnnotationQueries.java

@Override
public List<Annotation> readSurveyResponseAnnotations(final UUID surveyId) throws DataAccessException {
    try {/* w w  w  .j av a2 s .  c  om*/
        return getJdbcTemplate().query(SQL_READ_SURVEY_RESPONSE_ANNOTATION,
                new Object[] { surveyId.toString() }, new RowMapper<Annotation>() {
                    public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException {
                        try {
                            return new Annotation(rs.getString(1), rs.getString(2), rs.getLong(3),
                                    rs.getString(4));
                        } catch (DomainException e) {
                            throw new SQLException("Error creating an annotation object.", e);
                        }
                    }
                });
    } catch (org.springframework.dao.DataAccessException e) {
        throw new DataAccessException("An error occurred when running the following SQL: '"
                + SQL_READ_SURVEY_RESPONSE_ANNOTATION + " with the parameter " + surveyId, e);
    }
}

From source file:hu.bme.mit.trainbenchmark.sql.SQLDatabaseDriver.java

@Override
public List<Long> collectOutgoingConnectedVertices(final Long sourceVertex, final String sourceVertexType,
        final String targetVertexType, final String edgeType) throws IOException {
    final List<Long> results = new ArrayList<>();

    try {/* w  ww .ja  v  a2s. c o m*/
        final Statement statement = con.createStatement();
        final ResultSet rs = statement.executeQuery(String.format("SELECT * FROM `%s` WHERE `%s` = %s;",
                EDGE_TABLE.get(edgeType), EDGE_SOURCE_TYPES.get(edgeType), sourceVertex));
        while (rs.next()) {
            results.add(rs.getLong(2));
        }
    } catch (final SQLException e) {
        throw new IOException(e);
    }
    return results;
}

From source file:com.l2jfree.gameserver.communitybbs.bb.Post.java

/**
 * @param t/*  w  w w. ja  v  a  2  s.  c o  m*/
 */
private void load(Topic t) {
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con.prepareStatement(
                "SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC");
        statement.setInt(1, t.getForumID());
        statement.setInt(2, t.getID());
        ResultSet result = statement.executeQuery();
        while (result.next()) {
            CPost cp = new CPost();
            cp.postId = result.getInt("post_id");
            cp.postOwner = result.getString("post_owner_name");
            cp.postOwnerId = result.getInt("post_ownerid");
            cp.postDate = result.getLong("post_date");
            cp.postTopicId = result.getInt("post_topic_id");
            cp.postForumId = result.getInt("post_forum_id");
            cp.postTxt = result.getString("post_txt");
            _post.add(cp);
        }
        result.close();
        statement.close();
    } catch (Exception e) {
        _log.warn("data error on Post " + t.getForumID() + "/" + t.getID() + " : ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}