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:at.alladin.rmbt.db.Table.java

protected void setValuesFromResult(final ResultSet rs) throws SQLException {
    uid = rs.getLong("uid");

    for (final Field field : fields)
        field.setField(rs);/*from  w w w  .j  a  v a  2 s  . c  o  m*/
}

From source file:org.sakaiproject.tool.tasklist.impl.TaskRowMapper.java

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
    Task task = new TaskImpl();
    task.setId(new Long(rs.getLong(TASK_ID)));
    task.setOwner(rs.getString(TASK_OWNER));
    task.setSiteId(rs.getString(TASK_SITE_ID));
    task.setCreationDate(rs.getDate(TASK_CREATION_DATE));
    task.setTask(rs.getString(TASK_TEXT));
    return task;/*from ww  w .jav  a  2 s.  c o  m*/
}

From source file:com.chariotsolutions.crowd.connector.PrincipalRowMapper.java

public RemotePrincipal mapRow(ResultSet rs, int i) throws SQLException {

    long id = rs.getLong("id");
    String username = rs.getString("user_name");
    String email = rs.getString("email");
    String firstName = rs.getString("first_name");
    String lastName = rs.getString("last_name");
    String company = rs.getString("company");
    String title = rs.getString("title");
    String phone = rs.getString("phone");
    String country = rs.getString("country");

    String password = rs.getString("password");
    PasswordCredential credential = new PasswordCredential(password, true);

    boolean active = !rs.getBoolean("account_disabled");
    Date created = rs.getDate("created");

    RemotePrincipal principal = new RemotePrincipal();

    principal.setID(id);/*from w w w.ja v  a 2 s . com*/
    principal.setName(username);
    principal.setEmail(email);
    principal.setActive(active);
    principal.setAttribute(RemotePrincipal.FIRSTNAME, firstName);
    principal.setAttribute(RemotePrincipal.LASTNAME, lastName);
    principal.setAttribute(RemotePrincipal.DISPLAYNAME, firstName + " " + lastName);

    principal.setAttribute("company", company);
    principal.setAttribute("title", title);
    principal.setAttribute("phone", phone);
    principal.setAttribute("country", country);

    principal.setConception(created);

    principal.setCredentials(Collections.singletonList(credential));
    principal.setCredentialHistory(Collections.singletonList(credential));

    return principal;
}

From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java

private static final void loadItemCategoryCounts(AuctionMarkProfile profile, ResultSet vt) throws SQLException {
    while (vt.next()) {
        int col = 1;
        long i_c_id = vt.getLong(col++);
        int count = vt.getInt(col++);
        profile.items_per_category.put((int) i_c_id, count);
    } // WHILE//from  www.j  ava 2 s .  c  om
    if (LOG.isDebugEnabled())
        LOG.debug(String.format("Loaded %d CATEGORY records from %s",
                profile.items_per_category.getValueCount(), AuctionMarkConstants.TABLENAME_ITEM));
}

From source file:dk.netarkivet.common.utils.DBUtils.java

/**
 * Execute an SQL statement and return the set of Long-objects
 * in its result set./*from   w  w w.  j a v  a2  s . c  o  m*/
 *
 * NB: the provided connection is not closed.
 *
 * @param connection connection to the database.
 * @param query the given sql-query (must not be null or empty string)
 * @param args The arguments to insert into this query
 * @return the set of Long-objects in its result set
 */
public static Set<Long> selectLongSet(Connection connection, String query, Object... args) {
    ArgumentNotValid.checkNotNull(connection, "Connection connection");
    ArgumentNotValid.checkNotNullOrEmpty(query, "String query");
    ArgumentNotValid.checkNotNull(args, "Object... args");
    PreparedStatement s = null;
    try {
        s = prepareStatement(connection, query, args);
        ResultSet result = s.executeQuery();
        Set<Long> results = new TreeSet<Long>();
        while (result.next()) {
            if (result.getLong(1) == 0L && result.wasNull()) {
                String warning = "NULL value encountered in query: " + query;
                log.warn(warning);
            }
            results.add(result.getLong(1));
        }
        return results;
    } catch (SQLException e) {
        throw new IOFailure("Error preparing SQL statement " + query + " args " + Arrays.toString(args) + "\n"
                + ExceptionUtils.getSQLExceptionCause(e), e);
    } finally {
        closeStatementIfOpen(s);
    }
}

From source file:dk.netarkivet.common.utils.DBUtils.java

/**
 * Execute an SQL statement and return the list of Long-objects
 * in its result set./* w  w  w.  ja v a2s  .c  o m*/
 *
 * NB: the provided connection is not closed.
 *
 * @param connection connection to the database.
 * @param query the given sql-query (must not be null or empty string)
 * @param args The arguments to insert into this query
 * @return the list of Long-objects in its result set
 */
public static List<Long> selectLongList(Connection connection, String query, Object... args) {
    ArgumentNotValid.checkNotNull(connection, "Connection connection");
    ArgumentNotValid.checkNotNullOrEmpty(query, "String query");
    ArgumentNotValid.checkNotNull(args, "Object... args");
    PreparedStatement s = null;
    try {
        s = prepareStatement(connection, query, args);
        ResultSet result = s.executeQuery();
        List<Long> results = new ArrayList<Long>();
        while (result.next()) {
            if (result.getLong(1) == 0L && result.wasNull()) {
                String warning = "NULL value encountered in query: " + query;
                log.warn(warning);
            }
            results.add(result.getLong(1));
        }
        return results;
    } catch (SQLException e) {
        throw new IOFailure("Error preparing SQL statement " + query + " args " + Arrays.toString(args) + "\n"
                + ExceptionUtils.getSQLExceptionCause(e), e);
    } finally {
        closeStatementIfOpen(s);
    }
}

From source file:com.traveltainment.itea.bernat.contactwebapp.mvcmodel.jpa.ContactRepository.java

public List<Contact> findAll() {
    return jdbc.query(
            "select id, firstName, lastName, phoneNumber, emailAddress " + "from contacts order by lastName",
            (ResultSet rs, int rowNum) -> {
                Contact contact = new Contact();
                contact.setId(rs.getLong(1));
                contact.setFirstName(rs.getString(2));
                contact.setLastName(rs.getString(3));
                contact.setPhoneNumber(rs.getString(4));
                contact.setEmailAddress(rs.getString(5));
                return contact;
            });/*  w  w  w. ja  v a2  s.c o  m*/
}

From source file:net.mindengine.oculus.frontend.service.report.filter.JdbcFilterDAO.java

@Override
public long createFilter(Filter filter) throws Exception {
    String sql = "insert into filters (name, description, user_id, date, filter) values (?,?,?,?,?)";
    PreparedStatement ps = getConnection().prepareStatement(sql);

    ps.setString(1, filter.getName());//from ww  w  . jav a2s  .c om
    ps.setString(2, filter.getDescription());
    ps.setLong(3, filter.getUserId());
    ps.setTimestamp(4, new Timestamp(filter.getDate().getTime()));
    ps.setString(5, filter.getFilter());

    logger.info(ps);
    ps.execute();

    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        return rs.getLong(1);
    }
    return 0;
}

From source file:com.exploringspatial.com.exploringspatial.dao.mapping.CodeCategoryRowMapper.java

@Override
public CodeCategory mapRow(ResultSet resultSet, int i) throws SQLException {
    final CodeCategory codeCategory = new CodeCategory();
    codeCategory.setCodeCategoryPk(resultSet.getLong(CodeCategoryColumns.CODE_CATEGORY_PK.name()));
    codeCategory.setCategory(resultSet.getString(CodeCategoryColumns.CATEGORY.name()));
    return codeCategory;
}

From source file:com.flexive.core.Database.java

/**
 * Load a FxString from a translation table
 *
 * @param con         an open connection
 * @param table       the base table (NOT the one with translations!)
 * @param column      the name of the columns from the translations table to load
 * @param whereClause mandatory where clause
 * @return FxString created from the data table
 * @throws SQLException if a database error occured
 *///from  w  ww.  j  av a  2s  . co  m
public static FxString loadFxString(Connection con, String table, String column, String whereClause)
        throws SQLException {
    Statement stmt = null;
    Map<Long, String> hmTrans = new HashMap<Long, String>(10);
    long defaultLanguageId = -1;
    try {
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT LANG, DEFLANG, " + column + " FROM " + table + DatabaseConst.ML
                + " WHERE " + whereClause);
        while (rs != null && rs.next()) {
            hmTrans.put(rs.getLong(1), rs.getString(3));
            if (rs.getBoolean(2)) {
                defaultLanguageId = rs.getInt(1);
            }
        }
    } finally {
        if (stmt != null)
            stmt.close();
    }
    return new FxString(defaultLanguageId, hmTrans);
}