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:dsd.dao.WorstCaseDAO.java

public static long GetCount(boolean traffic, boolean debris) {
    long count = 0;
    try {//from   ww w.  ja  v  a  2  s .  c  o m
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            String tableName = GetTableNameForDataType(traffic, debris);
            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:common.DBHelper.java

/**
 * Extract key from given ResultSet.//from ww w .j a  va  2  s  . co m
 *
 * @param key resultSet with key
 * @return key from given result set
 * @throws SQLException when operation fails
 */
public static Long getId(ResultSet key) throws SQLException {
    if (key.getMetaData().getColumnCount() != 1) {
        throw new IllegalArgumentException("Given ResultSet contains more columns");
    }
    if (key.next()) {
        Long result = key.getLong(1);
        if (key.next()) {
            throw new IllegalArgumentException("Given ResultSet contains more rows");
        }
        return result;
    } else {
        throw new IllegalArgumentException("Given ResultSet contain no rows");
    }
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * returns profile based on id//  w  ww.ja v  a  2 s. c o m
 *
 * @param con db connection object
 * @param profileId profile id
 * @return profile
 */
public static Profile getProfile(Connection con, Long profileId) {

    Profile profile = null;
    try {
        PreparedStatement stmt = con.prepareStatement("select * from profiles where id=?");
        stmt.setLong(1, profileId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            profile = new Profile();
            profile.setId(rs.getLong("id"));
            profile.setNm(rs.getString("nm"));
            profile.setDesc(rs.getString("desc"));
            profile.setHostSystemList(ProfileSystemsDB.getSystemsByProfile(con, profileId));

        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }

    return profile;
}

From source file:com.keybox.manage.db.ProfileDB.java

/**
 * returns all profile information/* w w  w  . j  a v a  2s. c om*/
 *
 * @return list of profiles
 */
public static List<Profile> getAllProfiles() {

    ArrayList<Profile> profileList = new ArrayList<>();
    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement("select * from  profiles order by nm asc");
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            Profile profile = new Profile();
            profile.setId(rs.getLong("id"));
            profile.setNm(rs.getString("nm"));
            profile.setDesc(rs.getString("desc"));
            profileList.add(profile);

        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    } finally {
        DBUtils.closeConn(con);
    }

    return profileList;
}

From source file:dsd.dao.CalculatedDataDAO.java

public static long GetCount(eCalculatedDataType eDataType) {
    long count = 0;
    try {//from ww  w  . ja v a  2  s .  c  o  m
        Connection con = DAOProvider.getDataSource().getConnection();
        try {
            String tableName = GetTableNameForDataType(eDataType);
            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:com.tethrnet.manage.db.SystemStatusDB.java

/**
 * returns the first system that authorized keys has not been tried
 *
 * @param userId user id/* w  ww.j a va  2  s.  com*/
 * @return hostSystem systems for authorized_keys replacement
 */
public static HostSystem getNextPendingSystem(Long userId) {

    HostSystem hostSystem = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement(
                "select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc");
        stmt.setString(1, HostSystem.INITIAL_STATUS);
        stmt.setString(2, HostSystem.AUTH_FAIL_STATUS);
        stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS);
        stmt.setLong(4, userId);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString("status_cd"));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

From source file:com.tethrnet.manage.db.SystemStatusDB.java

/**
 * returns key placement status of system
 *
 * @param systemId system id//from   ww w  .j a va 2s  . c  o m
 * @param userId user id
 */
public static HostSystem getSystemStatus(Long systemId, Long userId) {

    Connection con = null;
    HostSystem hostSystem = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?");
        stmt.setLong(1, systemId);
        stmt.setLong(2, userId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString("status_cd"));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * returns the first system that authorized keys has not been tried
 *
 * @param userId user id/*  ww  w.j  av  a 2  s.  co m*/
 * @return hostSystem systems for authorized_keys replacement
 */
public static HostSystem getNextPendingSystem(Long userId) {

    HostSystem hostSystem = null;
    Connection con = null;
    try {
        con = DBUtils.getConn();
        PreparedStatement stmt = con.prepareStatement(
                "select * from status where (status_cd like ? or status_cd like ? or status_cd like ?) and user_id=? order by id asc");
        stmt.setString(1, HostSystem.INITIAL_STATUS);
        stmt.setString(2, HostSystem.AUTH_FAIL_STATUS);
        stmt.setString(3, HostSystem.PUBLIC_KEY_FAIL_STATUS);
        stmt.setLong(4, userId);
        ResultSet rs = stmt.executeQuery();

        if (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString(STATUS_CD));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

From source file:com.keybox.manage.db.SystemStatusDB.java

/**
 * returns key placement status of system
 *
 * @param systemId system id/*from ww w  .j a  v  a 2 s.c  o m*/
 * @param userId user id
 */
public static HostSystem getSystemStatus(Long systemId, Long userId) {

    Connection con = null;
    HostSystem hostSystem = null;
    try {
        con = DBUtils.getConn();

        PreparedStatement stmt = con.prepareStatement("select * from status where id=? and user_id=?");
        stmt.setLong(1, systemId);
        stmt.setLong(2, userId);
        ResultSet rs = stmt.executeQuery();

        while (rs.next()) {
            hostSystem = SystemDB.getSystem(con, rs.getLong("id"));
            hostSystem.setStatusCd(rs.getString(STATUS_CD));
        }
        DBUtils.closeRs(rs);
        DBUtils.closeStmt(stmt);

    } catch (Exception e) {
        log.error(e.toString(), e);
    }
    DBUtils.closeConn(con);
    return hostSystem;

}

From source file:ch.newscron.registration.UserRegistration.java

private static List<User> parseResultSet(ResultSet resultSet) {
    List<User> userList = new ArrayList<>();
    try {/*from   w w  w.  j av a  2  s  .  c om*/
        while (resultSet.next()) {
            User newUser = new User(resultSet.getString("name"), resultSet.getString("lastName"),
                    resultSet.getString("email"), resultSet.getLong("campaignId"),
                    resultSet.getString("custID"), resultSet.getString("shortURL"));
            userList.add(newUser);
        }
        return userList;
    } catch (SQLException ex) {
        Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex);
    }

    return null;
}