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:com.senior.g40.service.UserService.java

private static void setUser(ResultSet rs, User usr) throws SQLException {
    usr.setUserId(rs.getLong(""));
    usr.setUsername(rs.getString(""));
    usr.setPassword(rs.getString(""));
    usr.setUserType(rs.getString("").charAt(0));
}

From source file:com.senior.g40.service.UserService.java

private static void setProfile(ResultSet rs, Profile pf) throws SQLException {
    pf.setUserId(rs.getLong("userId"));
    pf.setFirstName(rs.getString("firstName"));
    pf.setLastName(rs.getString("lastName"));
    pf.setPersonalId(rs.getLong("personalId"));
    pf.setPhoneNumber(rs.getString("phone"));
    pf.setAddress1(rs.getString("address1"));
    pf.setAddress2(rs.getString("address2"));
    pf.setAge(rs.getInt("age"));
    pf.setGender(rs.getString("gender").charAt(0));
}

From source file:com.acme.spring.jdbc.JdbcTestHelper.java

/**
 * <p>Retrieves all the stocks from database, using passed {@link JdbcTemplate}.</p>
 *
 * @param jdbcTemplate the jdbc template to use
 *
 * @return list of stocks retrieved from database
 *///from w  w w .j av a2 s .co m
public static List<Stock> retrieveAllStocks(JdbcTemplate jdbcTemplate) {

    return jdbcTemplate.query("select id, name, symbol, value, date from Stock order by name",
            new RowMapper<Stock>() {
                public Stock mapRow(ResultSet rs, int rowNum) throws SQLException {

                    int index = 1;

                    Stock result = new Stock();
                    result.setId(rs.getLong(index++));
                    result.setName(rs.getString(index++));
                    result.setSymbol(rs.getString(index++));
                    result.setValue(rs.getBigDecimal(index++));
                    result.setDate(rs.getDate(index++));

                    return result;
                }
            });
}

From source file:com.thoughtworks.go.server.datamigration.M001.java

static Migration convertPipelineSelectionsToFilters() {
    return (cxn) -> {
        if (!required(cxn))
            return;

        try (Statement s = cxn.createStatement()) {
            final ResultSet rs = s.executeQuery(
                    "SELECT id, selections, isblacklist FROM pipelineselections WHERE version = 0");
            while (rs.next()) {
                perform(cxn, rs.getLong(ID), rs.getString(SELECTIONS), rs.getBoolean(BLACKLIST));
            }/* w w w.  ja v  a2 s  .  co  m*/
        }
    };
}

From source file:net.sf.sprockets.sql.Statements.java

/**
 * Execute the query, get the long values in the first column of the result set, and close the
 * statement./* ww  w. j ava 2 s  .c  o m*/
 * 
 * @param stmt
 *            must already have parameters set
 * @return null if the result set is empty
 * @since 1.4.0
 */
public static long[] allLongs(PreparedStatement stmt) throws SQLException {
    long[] l = null;
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
        LongList list = new ArrayLongList();
        do {
            list.add(rs.getLong(1));
        } while (rs.next());
        l = list.toArray();
    }
    stmt.close();
    return l;
}

From source file:cn.edu.zju.acm.onlinejudge.persistence.sql.Database.java

/**
 * Gets the last id./*from w w w  .  ja  v a2  s  .c o m*/
 * 
 * @param conn
 * @param ps
 * @param rs
 * @return the last id
 * @throws SQLException
 */
public static long getLastId(Connection conn) throws SQLException {
    PreparedStatement ps = null;
    try {
        ps = conn.prepareStatement(Database.GET_LAST_ID);
        ResultSet rs = ps.executeQuery();
        rs.next();
        return rs.getLong(1);
    } finally {
        Database.dispose(ps);
    }
}

From source file:dsd.dao.RawDataDAO.java

public static long GetCount() {
    long count = 0;
    try {//from  ww w.  ja  va  2s. co m
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " count(*) ", "", "", con, null);
            while (results.next()) {
                count = results.getLong(1);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return count;
}

From source file:net.sf.sprockets.sql.Statements.java

/**
 * Execute the query, get the long values in the first row of the result set, and close the
 * statement./*from  w  ww.ja v  a  2  s. co  m*/
 * 
 * @param stmt
 *            must already have parameters set
 * @return null if the result set is empty
 * @since 1.4.0
 */
public static long[] firstLongRow(PreparedStatement stmt) throws SQLException {
    long[] l = null;
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
        l = new long[rs.getMetaData().getColumnCount()];
        for (int i = 0; i < l.length; i++) {
            l[i] = rs.getLong(i + 1);
        }
    }
    stmt.close();
    return l;
}

From source file:at.alladin.rmbt.db.dao.QoSTestResultDao.java

/**
 * //w  w w .  j a va  2  s. c o m
 * @param rs
 * @return
 * @throws SQLException 
 */
private static QoSTestResult instantiateItem(ResultSet rs) throws SQLException {
    QoSTestResult result = new QoSTestResult();

    result.setUid(rs.getLong("uid"));
    result.setTestType(rs.getString("test"));
    result.setResults(rs.getString("result"));
    result.setTestUid(rs.getLong("test_uid"));
    result.setQoSTestObjectiveId(rs.getLong("qos_test_uid"));
    result.setTestDescription(rs.getString("test_desc"));
    result.setTestSummary(rs.getString("test_summary"));
    result.setSuccessCounter(rs.getInt("success_count"));
    result.setFailureCounter(rs.getInt("failure_count"));

    final String results = rs.getString("results");
    try {
        result.setExpectedResults(results != null ? new JSONArray(results) : null);
    } catch (JSONException e) {
        result.setExpectedResults(null);
        e.printStackTrace();
    }

    return result;
}

From source file:dsd.dao.ParsedInputFilesDAO.java

public static long GetCount(eFileType fileType) {
    long count = 0;
    try {/*from  w  w w.  j a v  a 2 s  . c o m*/
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            Object[] parameters = new Object[1];
            parameters[0] = new Integer(fileType.getCode());
            ResultSet results = DAOProvider.SelectTableSecure(tableName, " count(*) ", " type = ? ", "", con,
                    parameters);
            while (results.next()) {
                count = results.getLong(1);
            }
        } catch (Exception exc) {
            exc.printStackTrace();
        }
        con.close();
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return count;
}