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:net.sf.l2j.gameserver.model.entity.L2JOneoRusEvents.DM.java

public static void loadData() {
    _eventName = new String();
    _eventDesc = new String();
    _joiningLocationName = new String();
    _savePlayers = new Vector<String>();
    _players = new Vector<L2PcInstance>();
    _topPlayer = null;/*from  ww w . j av a  2s .  c  o m*/
    _npcSpawn = null;
    _joining = false;
    _teleport = false;
    _started = false;
    _sitForced = false;
    _npcId = 0;
    _npcX = 0;
    _npcY = 0;
    _npcZ = 0;
    _rewardId = 0;
    _rewardAmount = 0;
    _topKills = 0;
    _minlvl = 0;
    _maxlvl = 0;
    _playerColors = 0;
    _playerX = 0;
    _playerY = 0;
    _playerZ = 0;
    java.sql.Connection con = null;
    try {
        PreparedStatement statement;
        ResultSet rs;
        con = L2DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("Select * from dm");
        rs = statement.executeQuery();
        while (rs.next()) {
            _eventName = rs.getString("eventName");
            _eventDesc = rs.getString("eventDesc");
            _joiningLocationName = rs.getString("joiningLocation");
            _minlvl = rs.getInt("minlvl");
            _maxlvl = rs.getInt("maxlvl");
            _npcId = rs.getInt("npcId");
            _npcX = rs.getInt("npcX");
            _npcY = rs.getInt("npcY");
            _npcZ = rs.getInt("npcZ");
            _rewardId = rs.getInt("rewardId");
            _rewardAmount = rs.getInt("rewardAmount");
            _playerColors = rs.getInt("color");
            _playerX = rs.getInt("playerX");
            _playerY = rs.getInt("playerY");
            _playerZ = rs.getInt("playerZ");
        }
        statement.close();
    } catch (Exception e) {
        _log.error("Exception: DM.loadData(): " + e.getMessage());
    } finally {
        try {
            con.close();
        } catch (Exception e) {
        }
    }
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanup.java

/**
 * /*from  w  w w .j  a  va2s  .  co  m*/
 */
public static void fixTaxa() {
    String connectStr = "jdbc:mysql://localhost/";

    String dbName = "kevin";

    DBConnection dbc = new DBConnection("root", "root", connectStr + dbName, "com.mysql.jdbc.Driver",
            "org.hibernate.dialect.MySQLDialect", dbName);
    Connection conn = dbc.createConnection();
    BasicSQLUtils.setDBConnection(conn);

    try {
        // Fix Catalog Numbers
        String sql = "SELECT COUNT(*) FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        System.out.println("CatNum to be fixed: " + BasicSQLUtils.getCountAsInt(sql));

        PreparedStatement pTxStmt = conn
                .prepareStatement("UPDATE collectionobject SET CatalogNumber=? WHERE CollectionObjectID = ?");
        sql = "SELECT CatalogNumber, CollectionObjectID FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        for (Object[] cols : BasicSQLUtils.query(sql)) {
            String catNum = cols[0].toString();
            catNum = StringUtils.replace(catNum, "COLE ", "COLE");

            pTxStmt.setString(1, catNum);
            pTxStmt.setInt(2, (Integer) cols[1]);

            if (pTxStmt.executeUpdate() != 1) {
                System.out.println("Error deleting ColObjID: " + cols[1]);
            } else {
                System.out.println("Fixed ColObjID: " + cols[1]);
            }
        }
        pTxStmt.close();

        sql = "SELECT COUNT(*) FROM collectionobject WHERE CatalogNumber LIKE 'NHRS-COLE %'";
        System.out.println("CatNum not fixed: " + BasicSQLUtils.getCountAsInt(sql));

        // Fix Taxon - Start by finding all the duplicate Taxon Records
        sql = "SELECT Name FROM (SELECT Name, COUNT(Name) as cnt, TaxonID FROM taxon GROUP BY Name) T1 WHERE cnt > 1 AND TaxonID > 15156 ORDER BY cnt desc";

        Statement stmt = conn.createStatement();
        PreparedStatement pStmt = conn
                .prepareStatement("UPDATE determination SET TaxonID=? WHERE DeterminationID = ?");
        PreparedStatement pStmt2 = conn
                .prepareStatement("UPDATE determination SET PreferredTaxonID=? WHERE DeterminationID = ?");
        PreparedStatement pStmt3 = conn.prepareStatement("UPDATE taxon SET AcceptedID=? WHERE TaxonID = ?");
        PreparedStatement delStmt = conn.prepareStatement("DELETE FROM taxon WHERE TaxonID=?");

        int fixedCnt = 0;
        for (Object[] cols : BasicSQLUtils.query(sql)) {
            String name = cols[0].toString();

            sql = String.format("SELECT COUNT(*) FROM taxon WHERE Name = '%s' ORDER BY TaxonID ASC", name);
            System.out.println("------------------------------------" + name + " - "
                    + BasicSQLUtils.getCountAsInt(sql) + "-----------------------------------");

            // Find all duplicate Taxon Objects
            sql = String.format("SELECT TaxonID FROM taxon WHERE Name = '%s' ORDER BY TaxonID ASC", name);

            int c = 0;
            Integer firstID = null;

            ResultSet rs2 = stmt.executeQuery(sql);
            while (rs2.next()) {
                int id = rs2.getInt(1);
                if (c == 0) // Skip the first one which will the original
                {
                    firstID = id;
                    c = 1;
                    continue;
                }

                // Find all the determinations
                sql = String.format("SELECT DeterminationId FROM determination WHERE TaxonID = %d", id);
                System.out.println(sql);

                Vector<Integer> ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " determinations with TaxonID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer detId : ids) {
                    pStmt.setInt(1, firstID);
                    pStmt.setInt(2, detId);
                    if (pStmt.executeUpdate() != 1) {
                        System.out.println("Error updating DetId: " + detId);
                    } else {
                        System.out.print(detId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                // Find all the determinations
                sql = String.format("SELECT DeterminationId FROM determination WHERE PreferredTaxonID = %d", id,
                        id);
                System.out.println(sql);

                ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " determinations with PreferredTaxonID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer detId : ids) {
                    pStmt2.setInt(1, firstID);
                    pStmt2.setInt(2, detId);
                    if (pStmt2.executeUpdate() != 1) {
                        System.out.println("Error updating DetId: " + detId);
                    } else {
                        System.out.print(detId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                sql = String.format("SELECT TaxonID FROM taxon WHERE AcceptedID = %d", id);
                System.out.println(sql);

                ids = BasicSQLUtils.queryForInts(conn, sql);
                System.out.println("Fixing " + ids.size() + " taxon with AcceptedID: " + id
                        + " Setting to orig TaxonID: " + firstID);
                for (Integer taxId : ids) {
                    pStmt3.setInt(1, firstID);
                    pStmt3.setInt(2, taxId);
                    if (pStmt3.executeUpdate() != 1) {
                        System.out.println("Error updating TaxId: " + taxId);
                    } else {
                        System.out.print(taxId + ", ");
                        fixedCnt++;
                    }
                }
                System.out.println();

                sql = "SELECT COUNT(*) FROM taxon WHERE ParentID = " + id;
                System.out.println(sql);

                if (BasicSQLUtils.getCountAsInt(sql) == 0) {
                    delStmt.setInt(1, id);
                    if (delStmt.executeUpdate() != 1) {
                        System.out.println("Error deleting TaxonID: " + id);
                    } else {
                        System.out.println("Deleted TaxonID: " + id);
                    }
                } else {
                    System.out.println("Unable to delete TaxonID: " + id + " it is a parent.");
                }
                c++;
            }
            rs2.close();

            int detCnt = BasicSQLUtils
                    .getCountAsInt("SELECT COUNT(*) FROM determination WHERE TaxonID = " + firstID);
            if (detCnt > 0) {
                System.out.println(detCnt + " Determinations still using TaxonID: " + firstID);
            }
        }

        stmt.close();
        pStmt.close();

        System.out.println("Fixed Det Ids: " + fixedCnt);

    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

From source file:springmvc.repository.mappers.GameIDMapper.java

public Integer mapRow(ResultSet rs, int i) throws SQLException {
    return rs.getInt("idgamemulti");
}

From source file:org.aksw.gerbil.database.IntegerRowMapper.java

@Override
public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
    return rs.getInt(1);
}

From source file:de.langmi.spring.batch.examples.readers.jdbc.StringRowMapper.java

@Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
    return String.valueOf(rs.getInt(1)) + "," + rs.getString(2);
}

From source file:ru.mystamps.web.dao.impl.SitemapInfoDtoRowMapper.java

@Override
public SitemapInfoDto mapRow(ResultSet resultSet, int i) throws SQLException {
    Integer id = resultSet.getInt("id");
    Date updatedAt = resultSet.getTimestamp("updated_at");

    return new SitemapInfoDto(id, updatedAt);
}

From source file:org.works.integration.support.CoffeBeverageMapper.java

public CoffeeBeverage mapRow(ResultSet rs, int rowNum) throws SQLException {
    return new CoffeeBeverage(rs.getInt("ID"), rs.getString("COFFEE_NAME"), rs.getString("COFFEE_DESCRIPTION"));
}

From source file:ru.mystamps.web.dao.impl.LinkEntityDtoRowMapper.java

@Override
public LinkEntityDto mapRow(ResultSet resultSet, int i) throws SQLException {
    Integer collectionId = resultSet.getInt("collection_id");
    String collectionSlug = resultSet.getString("collection_slug");
    String ownerName = resultSet.getString("owner_name");

    return new LinkEntityDto(collectionId, collectionSlug, ownerName);
}

From source file:HSqlManager.java

public static void runChecks(Connection connection) throws SQLException, IOException, IllegalAccessException,
        InstantiationException, ClassNotFoundException {
    INSTANCE = ImportPhagelist.getInstance();
    checkPhage(connection);//w  w  w  .j ava 2  s .  com
    Statement s = connection.createStatement();
    ResultSet rs = s.executeQuery("Select Distinct Bp FROM primerdb.primers");
    Set<Integer> bpset = new HashSet<>();
    while (rs.next()) {
        bpset.add(rs.getInt("Bp"));
    }
    for (int bp : bpset) {
        commonClusterNewPhages(connection, bp);
        if (newPhages.size() != 0)
            uniqueDB(connection, bp);
    }
}

From source file:org.cbarrett.lcbo.db.mapper.LCBODatasetExtractor.java

@Override
public Dataset extractData(ResultSet rs) throws SQLException {
    Dataset ds = new Dataset();
    ds.setId(rs.getInt(1));
    ds.setCsvDump(rs.getString(2));/* ww  w. j  ava  2  s .  c  o m*/
    return ds;
}