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:org.apache.drill.test.framework.Utils.java

public static int getNumberOfDrillbits(Connection connection) {
    String query = "select count(*) from sys.drillbits";
    int numberOfDrillbits = 0;
    try {/*from ww  w .j  av a2s. co  m*/
        ResultSet resultSet = execSQL(query, connection);
        resultSet.next();
        numberOfDrillbits = resultSet.getInt(1);
    } catch (SQLException e) {
        LOG.error(e.getMessage());
        e.printStackTrace();
    }
    return numberOfDrillbits;
}

From source file:com.aurel.track.dbase.UpdateDbSchema.java

/**
 * Gets the database version/*from  ww  w.j  av a 2  s  . c  om*/
 * @param dbConnection
 * @return
 */
public static int getDBVersion(Connection dbConnection) {
    Statement istmt = null;
    ResultSet rs = null;
    try {
        istmt = dbConnection.createStatement();
        rs = istmt.executeQuery("SELECT DBVERSION FROM TSITE");
        if (rs == null || !rs.next()) {
            LOGGER.info("TSITE is empty.");
        } else {
            return rs.getInt(1);
        }
    } catch (Exception e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception e) {
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        try {
            if (istmt != null) {
                istmt.close();
            }
        } catch (Exception e) {
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
        } catch (Exception e) {
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return 0;
}

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

private static Object[] fillNPC(ResultSet rs) throws SQLException, IOException {
    final ObjectFactory factory = new ObjectFactory();

    final NPCTemplate template = factory.createNPCTemplate();
    template.setID(new NPCTemplateID(rs.getInt("idTemplate"), null));

    template.setController(controllers.get(rs.getString("type")));
    if (template.getController() == null)
        template.setController(NotImplementedNPCController.class);
    template.setInfo(factory.createNPCTemplateInfo());

    template.getInfo().setName(factory.createNPCTemplateInfoName());
    template.getInfo().getName().setValue(rs.getString("name"));
    // template.getInfo().getName().setDisplay(rs.getBoolean("show_name"));
    template.getInfo().getName().setSend(rs.getBoolean("serverSideName"));

    template.getInfo().setTitle(factory.createNPCTemplateInfoTitle());
    template.getInfo().getTitle().setValue(rs.getString("title"));
    template.getInfo().getTitle().setSend(rs.getBoolean("serverSideTitle"));

    if (template.getInfo().getName().getValue().length() == 0)
        template.getInfo().setName(null);
    if (template.getInfo().getTitle().getValue().length() == 0)
        template.getInfo().setTitle(null);

    template.getInfo().setLevel(rs.getInt("level"));
    template.getInfo().setRace(getRace(rs.getInt("race")));
    if (!rs.getString("sex").equals("etc"))
        template.getInfo().setSex(ActorSex.valueOf(rs.getString("sex").toUpperCase()));
    // template.info.attackable = rs.getBoolean("attackable");
    // template.getInfo().setTargetable(rs.getBoolean("targetable"));
    template.getInfo().setTargetable(true);
    // template.getInfo().setAggressive(rs.getBoolean("aggro"));
    template.getInfo().setAggressive(true);
    template.getInfo().setAttackable(true); // FIXME

    template.getInfo().setStats(factory.createNPCTemplateInfoStats());

    template.getInfo().getStats().setHp(factory.createNPCTemplateInfoStatsHp());
    template.getInfo().getStats().getHp().setMax(rs.getDouble("hp"));
    template.getInfo().getStats().getHp().setRegen(rs.getDouble("hpreg"));

    template.getInfo().getStats().setMp(factory.createNPCTemplateInfoStatsMp());
    template.getInfo().getStats().getMp().setMax(rs.getDouble("mp"));
    template.getInfo().getStats().getMp().setRegen(rs.getDouble("mpreg"));

    template.getInfo().getStats().setAttack(factory.createNPCTemplateInfoStatsAttack());
    template.getInfo().getStats().getAttack().setRange(rs.getInt("attackrange"));
    template.getInfo().getStats().getAttack().setCritical(rs.getInt("critical"));

    template.getInfo().getStats().getAttack().setPhysical(factory.createNPCTemplateInfoStatsAttackPhysical());
    template.getInfo().getStats().getAttack().getPhysical().setDamage(rs.getDouble("patk"));
    template.getInfo().getStats().getAttack().getPhysical().setSpeed(rs.getDouble("atkspd"));

    template.getInfo().getStats().getAttack().setMagical(factory.createNPCTemplateInfoStatsAttackMagical());
    template.getInfo().getStats().getAttack().getMagical().setDamage(rs.getDouble("matk"));
    template.getInfo().getStats().getAttack().getMagical().setSpeed(rs.getDouble("matkspd"));

    template.getInfo().getStats().setDefense(factory.createNPCTemplateInfoStatsDefense());
    template.getInfo().getStats().getDefense().setPhysical(factory.createNPCTemplateInfoStatsDefensePhysical());
    template.getInfo().getStats().getDefense().getPhysical().setValue(rs.getDouble("pdef"));
    template.getInfo().getStats().getDefense().setMagical(factory.createNPCTemplateInfoStatsDefenseMagical());
    template.getInfo().getStats().getDefense().getMagical().setValue(rs.getDouble("mdef"));

    template.getInfo().getStats().setMove(factory.createNPCTemplateInfoStatsMove());
    template.getInfo().getStats().getMove().setRun(rs.getDouble("runspd"));
    template.getInfo().getStats().getMove().setWalk(rs.getDouble("walkspd"));

    template.getInfo().getStats().setBase(factory.createNPCTemplateInfoStatsBase());
    template.getInfo().getStats().getBase().setInt(rs.getInt("int"));
    template.getInfo().getStats().getBase().setStr(rs.getInt("str"));
    template.getInfo().getStats().getBase().setCon(rs.getInt("con"));
    template.getInfo().getStats().getBase().setDex(rs.getInt("dex"));
    template.getInfo().getStats().getBase().setWit(rs.getInt("wit"));
    template.getInfo().getStats().getBase().setMen(rs.getInt("men"));

    template.getInfo().setExperience(rs.getLong("exp"));
    template.getInfo().setSp(rs.getInt("sp"));

    if (rs.getInt("rhand") > 0 || rs.getInt("lhand") > 0)
        template.getInfo().setItem(factory.createNPCTemplateInfoItem());
    if (rs.getInt("rhand") > 0)
        template.getInfo().getItem().setRightHand(new ItemTemplateID(rs.getInt("rhand"), null));
    if (rs.getInt("lhand") > 0)
        template.getInfo().getItem().setLeftHand(new ItemTemplateID(rs.getInt("lhand"), null));

    template.getInfo().setCollision(factory.createNPCTemplateInfoCollision());
    template.getInfo().getCollision().setRadius(rs.getDouble("collision_radius"));
    template.getInfo().getCollision().setHeigth(rs.getDouble("collision_height"));

    template.setDroplist(fillDropList(factory, rs, template.getID().getID()));
    template.setSkills(fillSkillList(factory, rs, template.getID().getID()));
    template.setTalk(fillHtmlChat(factory, template.getID().getID()));

    return new Object[] { template, createParentType(rs.getString("type")) };
}

From source file:com.asakusafw.bulkloader.testutil.UnitTestUtil.java

/**
 * ??// w w w. j  ava2 s .c om
 * @param tableName
 * @param expected
 * @return
 */
public static boolean countAssert(String tableName, int expected) throws Exception {
    String sql = "SELECT count(*) FROM " + tableName;
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        printLog("executeQuery???SQL" + sql, "countAssert");
        conn = DBConnection.getConnection();
        stmt = conn.prepareStatement(sql);
        rs = stmt.executeQuery();
        if (rs.next()) {
            int count = rs.getInt("count(*)");
            if (expected == count) {
                printLog("????" + count, "countAssert");
                return true;
            } else {
                printLog("??????" + tableName, "countAssert");
                return false;
            }
        } else {
            printLog("??????" + tableName, "countAssert");
            return false;
        }
    } finally {
        DBConnection.closeRs(rs);
        DBConnection.closePs(stmt);
        DBConnection.closeConn(conn);
    }
}

From source file:ca.qc.adinfo.rouge.achievement.db.AchievementDb.java

public static HashMap<String, Achievement> getAchievementList(DBManager dbManager) {

    Connection connection = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    HashMap<String, Achievement> returnValue = new HashMap<String, Achievement>();

    String sql = "SELECT `key`, `name`, `point_value`, `total` FROM rouge_achievements";
    try {// w w  w.j av  a  2s.c o  m
        connection = dbManager.getConnection();
        stmt = connection.prepareStatement(sql);

        rs = stmt.executeQuery();

        while (rs.next()) {

            String key = rs.getString("key");

            Achievement achievement = new Achievement(key, rs.getString("name"), rs.getInt("point_value"),
                    rs.getDouble("total"), 0);

            returnValue.put(key, achievement);
        }

        return returnValue;

    } catch (SQLException e) {
        log.error(stmt);
        log.error(e);
        return null;

    } finally {

        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(connection);
    }
}

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

/**
 * //from www. j  a  va2 s.c o m
 *
 * @return
 * @throws java.sql.SQLException
 */
public static TreeMap<Integer, String> GetAnnotatedData() throws SQLException {
    Statement stmt = connection.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM assignmentsdone;");
    TreeMap<Integer, String> dbJsonString = new TreeMap<>();
    //        ArrayList<String> dbJsonString = new ArrayList<>();
    while (rs.next()) {
        int json_id = rs.getInt("text_id");
        String json = rs.getString("json_out");
        dbJsonString.put(json_id, json);
    }
    return dbJsonString;
}

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

private static int lookupMailboxIdFromEmail(DbConnection conn, String email)
        throws SQLException, ServiceException {
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {/*from   ww  w. j a v  a  2  s .c  o m*/
        String sql = "SELECT id FROM mailbox WHERE comment=?";
        stmt = conn.prepareStatement(sql);
        stmt.setString(1, email.toUpperCase());
        rs = stmt.executeQuery();
        if (!rs.next())
            throw ServiceException.INVALID_REQUEST("Account " + email + " not found on this host", null);
        return rs.getInt(1);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
}

From source file:com.act.lcms.db.model.ScanFile.java

protected static List<ScanFile> fromResultSet(ResultSet resultSet) throws SQLException {
    List<ScanFile> results = new ArrayList<>();
    while (resultSet.next()) {
        Integer id = resultSet.getInt(DB_FIELD.ID.getOffset());
        String filename = resultSet.getString(DB_FIELD.FILENAME.getOffset());
        SCAN_MODE scanMode = SCAN_MODE.valueOf(resultSet.getString(DB_FIELD.MODE.getOffset()));
        SCAN_FILE_TYPE fileType = SCAN_FILE_TYPE.valueOf(resultSet.getString(DB_FIELD.FILE_TYPE.getOffset()));
        Integer plateId = resultSet.getInt(DB_FIELD.PLATE_ID.getOffset());
        if (resultSet.wasNull()) {
            plateId = null;/*ww  w .  j  a va 2  s.c om*/
        }
        Integer plateRow = resultSet.getInt(DB_FIELD.PLATE_ROW.getOffset());
        if (resultSet.wasNull()) {
            plateRow = null;
        }
        Integer plateColumn = resultSet.getInt(DB_FIELD.PLATE_COLUMN.getOffset());
        if (resultSet.wasNull()) {
            plateColumn = null;
        }
        results.add(new ScanFile(id, filename, scanMode, fileType, plateId, plateRow, plateColumn));
    }

    return results;
}

From source file:com.sql.SECExceptions.java

/**
 * Gathers a list of errors based on type and count total of them.
 *
 * @return// w  ww . j av  a  2  s .co  m
 */
public static List<SystemErrorModel> getErrorCounts() {
    List<SystemErrorModel> list = new ArrayList();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT exceptionType, COUNT(*) AS 'num' " + "FROM SECExceptions "
                + "WHERE timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) " + "GROUP BY exceptionType";
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        while (rs.next()) {
            SystemErrorModel item = new SystemErrorModel();
            item.setExceptionType(rs.getString("exceptionType") == null ? "" : rs.getString("exceptionType"));
            item.setNumber(rs.getInt("num"));
            list.add(item);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}

From source file:com.wso2telco.dep.reportingservice.dao.OperatorDAO.java

/**
 * Gets the SP list.//from  ww  w .  ja  v  a  2 s. com
 *
 * @param operator the operator
 * @return the SP list
 */
public static ArrayList<SPObject> getSPList(String operator) {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    String sql = "Select * from sub_approval_operators WHERE OPERATOR_LIST like '%" + operator + "%'";
    ArrayList<SPObject> spList = new ArrayList<SPObject>();
    try {
        conn = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        while (rs.next()) {
            SPObject spObject = new SPObject();
            spObject.setAppId(rs.getInt("APP_ID"));
            spList.add(spObject);

        }

    } catch (Exception e) {
        log.error("Error occured while getting approved operators of application from the database" + e);
    }
    return spList;
}