Example usage for java.sql ResultSet getInt

List of usage examples for java.sql ResultSet getInt

Introduction

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

Prototype

int getInt(String columnLabel) throws SQLException;

Source Link

Document

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

Usage

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

/**
 * returns terminal logs for user session for host system
 *
 * @param con       DB connection/*from   w ww.  j  a  v a 2s  . c o m*/
 * @param sessionId session id
 * @return session output for session
 */
public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) {

    List<HostSystem> hostSystemList = new ArrayList<HostSystem>();
    try {
        PreparedStatement stmt = con.prepareStatement(
                "select distinct instance_id, system_id from terminal_log where session_id=?");
        stmt.setLong(1, sessionId);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("system_id"));
            hostSystem.setInstanceId(rs.getInt("instance_id"));
            hostSystemList.add(hostSystem);
        }

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

    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
    return hostSystemList;

}

From source file:com.zimbra.cs.mailbox.util.MetadataDump.java

private static int getMailboxGroup(DbConnection conn, int mboxId) throws SQLException {
    int gid = 0;/*from w ww.  j  a  v a 2 s. co m*/
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = conn.prepareStatement("SELECT group_id FROM mailbox WHERE id = ?");
        stmt.setInt(1, mboxId);
        rs = stmt.executeQuery();
        if (rs.next())
            gid = rs.getInt(1);
    } finally {
        if (rs != null)
            rs.close();
        if (stmt != null)
            stmt.close();
    }
    return gid;
}

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

/**
 * returns terminal logs for user session for host system
 *
 * @param con       DB connection/*www . j  a va2 s.  c o  m*/
 * @param sessionId session id
 * @return session output for session
 */
public static List<HostSystem> getHostSystemsForSession(Connection con, Long sessionId) {

    List<HostSystem> hostSystemList = new ArrayList<>();
    try {
        PreparedStatement stmt = con.prepareStatement(
                "select distinct instance_id, system_id from terminal_log where session_id=?");
        stmt.setLong(1, sessionId);
        ResultSet rs = stmt.executeQuery();
        while (rs.next()) {
            HostSystem hostSystem = SystemDB.getSystem(con, rs.getLong("system_id"));
            hostSystem.setInstanceId(rs.getInt("instance_id"));
            hostSystemList.add(hostSystem);
        }

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

    } catch (Exception ex) {
        log.error(ex.toString(), ex);
    }
    return hostSystemList;

}

From source file:com.l2jserver.model.template.NPCTemplateConverter.java

private static Skills fillSkillList(final ObjectFactory factory, ResultSet npcRs, int npcId)
        throws SQLException {
    final Connection conn = npcRs.getStatement().getConnection();
    final Skills skills = factory.createNPCTemplateSkills();

    final PreparedStatement st = conn.prepareStatement("SELECT * FROM npcskills WHERE npcid = ?");
    st.setInt(1, npcId);//w  w  w  .  java2s  .c o  m
    st.execute();
    final ResultSet rs = st.getResultSet();
    while (rs.next()) {
        Skills.Skill s = factory.createNPCTemplateSkillsSkill();
        s.setId(new SkillTemplateID(rs.getInt("skillid"), null));
        s.setLevel(rs.getInt("level"));
        skills.getSkill().add(s);
    }
    if (skills.getSkill().size() == 0)
        return null;
    return skills;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getClusterDocuments(int clid) throws SQLException {
    TreeMap<Integer, String> all = new TreeMap<Integer, String>();
    String selectSQL = "SELECT palo_id,raw_text FROM texts_herc where text_id=" + clid + ";";
    ResultSet rs = connection.createStatement().executeQuery(selectSQL);
    while (rs.next()) {
        int tid = rs.getInt(1);
        String s = rs.getString(2);
        all.put(tid, s);//from w w  w  . ja  v a2s . c om
    }
    return all;
}

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:at.becast.youploader.database.SQLite.java

public static int saveTemplate(Template template) throws SQLException, IOException {
    PreparedStatement prest = null;
    ObjectMapper mapper = new ObjectMapper();
    String sql = "INSERT INTO `templates` (`name`, `data`) " + "VALUES (?,?)";
    prest = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    prest.setString(1, template.getName());
    prest.setString(2, mapper.writeValueAsString(template));
    prest.execute();/*w  w w  .  j  a  va2 s  .  c  om*/
    ResultSet rs = prest.getGeneratedKeys();
    prest.close();
    if (rs.next()) {
        int id = rs.getInt(1);
        rs.close();
        return id;
    } else {
        return -1;
    }
}

From source file:com.concursive.connect.web.modules.setup.utils.SetupUtils.java

/**
 * Determines if there is an administrative user configured in the database
 *
 * @param db// w  w w .  java  2s .c o m
 * @return
 */
public static boolean isAdminInstalled(Connection db) {
    int count = -1;
    try {
        PreparedStatement pst = db.prepareStatement(
                "SELECT count(*) AS recordcount " + "FROM users " + "WHERE access_admin = ? ");
        pst.setBoolean(1, true);
        ResultSet rs = pst.executeQuery();
        rs.next();
        count = rs.getInt("recordcount");
        rs.close();
        pst.close();
    } catch (Exception e) {
    }
    return count > 0;
}

From source file:com.concursive.connect.web.modules.setup.utils.SetupUtils.java

/**
 * Determines if a default project has been installed
 *
 * @param db/*ww  w .ja v a 2 s  . c  om*/
 * @return
 */
public static boolean isDefaultProjectInstalled(Connection db) {
    int count = -1;
    try {
        PreparedStatement pst = db.prepareStatement(
                "SELECT count(*) AS recordcount " + "FROM projects " + "WHERE system_default = ? ");
        pst.setBoolean(1, true);
        ResultSet rs = pst.executeQuery();
        rs.next();
        count = rs.getInt("recordcount");
        rs.close();
        pst.close();
    } catch (Exception e) {
    }
    return count > 0;
}

From source file:module.entities.NameFinder.DB.java

public static TreeMap<Integer, String> getDemocracitJSON(int consultation_id) throws SQLException {
    TreeMap<Integer, String> all = new TreeMap<Integer, String>();
    String selectSQL1 = "SELECT distinct consultation_id FROM enhancedentities;";
    ResultSet rs1 = connection.createStatement().executeQuery(selectSQL1);
    while (rs1.next()) {
        System.out.println(rs1.getString(1));
    }/*from  ww  w .j  av  a  2s.  c om*/
    String selectSQL = "SELECT article_id,json_text FROM enhancedentities where consultation_id="
            + consultation_id + ";";
    ResultSet rs = connection.createStatement().executeQuery(selectSQL);
    while (rs.next()) {
        int tid = rs.getInt(1);
        String s = rs.getString(2);
        all.put(tid, s);
    }
    return all;
}