Java Code Examples for java.sql.ResultSet.getInt()

The following are Jave code examples for showing how to use getInt() of the java.sql.ResultSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: SAPNetworkMonitor   File: MonitorMapper.java   View Source Code Vote up 6 votes
@Override
public Monitor map(int index, ResultSet r, StatementContext ctx) throws SQLException {

    int status = r.getInt("STATUS");
    boolean isUsable = true;
    if (status == 0) {
        isUsable = false;
    }

    Monitor monitor = Monitor.builder()
            .monitorId(r.getString("MONITOR_ID"))
            .version(r.getString("VERSION"))
            .name(r.getString("NAME"))
            .country(r.getString("COUNTRY"))
            .province(r.getString("PROVINCE"))
            .city(r.getString("CITY"))
            .isp(r.getString("ISP"))
            .area(r.getString("AREA"))
            .ip(r.getString("IP"))
            .nipingT(r.getString("NIPING_T"))
            .status(status)
            .isUsable(isUsable).build();

    monitor.set(r.getString("ACCOUNT_ID"), r.getDate("CREATION_TIME"), r.getDate("MODIFIED_TIME"));
    return monitor;
}
 
Example 2
Project: the-vigilantes   File: ConnectionRegressionTest.java   View Source Code Vote up 6 votes
/**
 * Test that we remain on the master when:
 * - the connection is not in read-only mode
 * - no slaves are configured
 * - a new slave is added
 */
public void testReplicationConnectionNoSlavesRemainOnMaster() throws Exception {
    Properties props = getPropertiesFromTestsuiteUrl();
    String masterHost = props.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY) + ":" + props.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);
    ReplicationConnection replConn = getTestReplicationConnectionNoSlaves(masterHost);
    Statement s = replConn.createStatement();
    ResultSet rs1 = s.executeQuery("select CONNECTION_ID()");
    assertTrue(rs1.next());
    int masterConnectionId = rs1.getInt(1);
    rs1.close();
    s.close();

    // add a slave and make sure we are NOT on a new connection
    replConn.addSlaveHost(masterHost);
    s = replConn.createStatement();
    rs1 = s.executeQuery("select CONNECTION_ID()");
    assertTrue(rs1.next());
    assertEquals(masterConnectionId, rs1.getInt(1));
    assertFalse(replConn.isReadOnly());
    rs1.close();
    s.close();
}
 
Example 3
Project: AeroStory   File: MaplePet.java   View Source Code Vote up 6 votes
public static int createPet(int itemid, byte level, int closeness, int fullness) {
    try {
        PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pets (name, level, closeness, fullness, summoned) VALUES (?, ?, ?, ?, 0)", Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, MapleItemInformationProvider.getInstance().getName(itemid));
        ps.setByte(2, level);
        ps.setInt(3, closeness);
        ps.setInt(4, fullness);
        ps.executeUpdate();
        ResultSet rs = ps.getGeneratedKeys();
        int ret = -1;
        if (rs.next()) {
            ret = rs.getInt(1);
            rs.close();
            ps.close();
        }
        return ret;
    } catch (SQLException e) {
        return -1;
    }
}
 
Example 4
Project: lams   File: StdJDBCDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Get the number of triggers in the given states that have
 * misfired - according to the given timestamp.
 * </p>
 * 
 * @param conn the DB Connection
 */
public int countMisfiredTriggersInState(
        Connection conn, String state1, long ts) throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(COUNT_MISFIRED_TRIGGERS_IN_STATE));
        ps.setBigDecimal(1, new BigDecimal(String.valueOf(ts)));
        ps.setString(2, state1);
        rs = ps.executeQuery();

        if (rs.next()) {
            return rs.getInt(1);
        }

        throw new SQLException("No misfired trigger count returned.");
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }
}
 
Example 5
Project: AdamantineShield   File: DataCache.java   View Source Code Vote up 6 votes
public Integer getDataId(Connection c, String data) throws SQLException {
	if (cache.containsKey(data))
		return cache.get(data);
	
	ResultSet r = c.createStatement().executeQuery("SELECT id FROM " + tableName + " WHERE " + dataRowName + " = '" + data + "'");
	if (!r.isBeforeFirst()) {
		c.createStatement().executeUpdate("INSERT INTO " + tableName + " (" + dataRowName + ") VALUES ('" + data + "');");
		r = c.createStatement().executeQuery("SELECT id FROM " + tableName + " WHERE " + dataRowName + " = '" + data + "'");
	}
	r.next();
	
	int result = r.getInt("id");
	r.close();
	
	cache.put(data, result);
	return result;
}
 
Example 6
Project: premier-wherehows   File: UserRowMapper.java   View Source Code Vote up 6 votes
@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException
{
    int id = rs.getInt(USER_ID_COLUMN);
    String name = rs.getString(USER_FULL_NAME_COLUMN);
    String email = rs.getString(USER_EMAIL_COLUMN);
    String username = rs.getString(USER_NAME_COLUMN);
    Integer departmentNum = rs.getInt(USER_DEPARTMENT_NUMBER_COLUMN);
    String defaultView = rs.getString(USER_SETTING_DETAIL_DEFAULT_VIEW_COLUMN);
    String defaultWatch = rs.getString(USER_SETTING_DEFAULT_WATCH_COLUMN);

    User user = new User();
    UserSetting userSetting = new UserSetting();
    userSetting.detailDefaultView = defaultView;
    userSetting.defaultWatch = defaultWatch;
    user.id = id;
    user.name = name;
    user.email = email;
    user.userName = username;
    user.departmentNum = departmentNum;
    user.userSetting = userSetting;

    return user;
}
 
Example 7
Project: waterrower-workout   File: WeightSelect.java   View Source Code Vote up 6 votes
@Override
public List<Weight> getResult(ResultSet resultSet) throws SQLException {
    List<Weight> result = new ArrayList<>();

    while (resultSet.next()) {

        int id = resultSet.getInt(WEIGHT_ID);
        double value = resultSet.getDouble(WEIGHT_VALUE);
        LocalDate created = convertDateToLocalDate(resultSet.getDate(WEIGHT_CREATED));
        int userId = resultSet.getInt(WEIGHT_FK_USER_ID);

        result.add(new Weight(id, value, created, userId));
    }

    return result;
}
 
Example 8
Project: mcClans   File: DatabaseLoader.java   View Source Code Vote up 6 votes
@Override
protected void loadAllies() {
    ResultSet clansResultSet = databaseConnectionOwner.executeQuery(GET_CLANS_ALLIES_QUERY);
    if (clansResultSet != null) {
        try {
            while (clansResultSet.next()) {
                int clanID = clansResultSet.getInt("clan_id");
                int clanIDAlly = clansResultSet.getInt("clan_id_ally");

                super.loadedAlly(clanID, clanIDAlly);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
 
Example 9
Project: L2J-Global   File: Announcement.java   View Source Code Vote up 5 votes
public Announcement(ResultSet rset) throws SQLException
{
	_id = rset.getInt("id");
	_type = AnnouncementType.findById(rset.getInt("type"));
	_content = rset.getString("content");
	_author = rset.getString("author");
}
 
Example 10
Project: mcClans   File: DatabaseUpgrade2.java   View Source Code Vote up 5 votes
private void updateClanIdColumn() {
    ResultSet clanResultSet = DatabaseConnectionOwner.getInstance().executeQuery(GET_CLANS_QUERY);
    if (clanResultSet != null) {
        try {
            while (clanResultSet.next()) {
                int clanId = clanResultSet.getInt("clan_id");
                UUID uuid = UUID.randomUUID();
                updateQuery("mcc_clans").value("bank_id", uuid.toString()).where("clan_id", clanId);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
 
Example 11
Project: nvx-apps   File: ItemPersister.java   View Source Code Vote up 5 votes
final private boolean itemExists(final String storeId) throws Exception {
    _itemExists.setString(1, storeId);
    ResultSet rs = _itemExists.executeQuery();
    try {
        return rs.next() && rs.getInt("N1") > 0;
    }
    finally {
        rs.close();
    }
}
 
Example 12
Project: SistemaAlmoxarifado   File: EntradaItemDAO.java   View Source Code Vote up 5 votes
public static EntradaItem retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM entrada_itens where id = " + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    return new EntradaItem(id,
            ProdutoDAO.retreave(rs.getInt("produto")),
            rs.getInt("entrada"),
            rs.getDouble("quantidade"),
            rs.getTimestamp("validade"),
            rs.getString("lote"),
            rs.getDouble("valor_unitario"));
}
 
Example 13
Project: hue   File: SchemaImportService.java   View Source Code Vote up 5 votes
public static Integer getRowCount(Datasource datasource, String schemaName, String tableName)
		throws ServiceException {

	DBType dbType = datasource.getDatabaseType();

	try (final Connection connection = ConnUtils.getNonSshConnection(datasource)) {
		String query = null;
		tableName = CommonUtils.removeQuotes(tableName);
		
		if (dbType == DBType.MYSQL || dbType == DBType.HIVE) {
			query = String.format(MYSQL_ROW_COUNT_QUERY, schemaName, tableName);
		}
		else if (dbType == DBType.POSTGRESQL || dbType == DBType.REDSHIFT 
				|| dbType == DBType.MSSQL || dbType == DBType.DERBY_LOCAL
				|| datasource.getDatabaseType() == DBType.AZURE
				|| datasource.getDatabaseType() == DBType.VERTICA) {
			query = String.format(ROW_COUNT_QUERY_WITH_SCHEMA, schemaName, tableName);
		}
		else {
			query = String.format(ROW_COUNT_QUERY, tableName);
		}

		logger.debug("Count Query = " + query);

		ResultSet rs = connection.createStatement().executeQuery(query);

		rs.next();
		return rs.getInt(1);
	}
	catch (Exception e) {
		throw new ServiceException(e);
	}
}
 
Example 14
Project: AeroStory   File: MapleGuild.java   View Source Code Vote up 5 votes
public static int createGuild(int leaderId, String name) {
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT guildid FROM guilds WHERE name = ?");
        ps.setString(1, name);
        ResultSet rs = ps.executeQuery();
        if (rs.first()) {
            ps.close();
            rs.close();
            return 0;
        }
        ps.close();
        rs.close();
        ps = con.prepareStatement("INSERT INTO guilds (`leader`, `name`, `signature`) VALUES (?, ?, ?)");
        ps.setInt(1, leaderId);
        ps.setString(2, name);
        ps.setInt(3, (int) System.currentTimeMillis());
        ps.execute();
        ps.close();
        ps = con.prepareStatement("SELECT guildid FROM guilds WHERE leader = ?");
        ps.setInt(1, leaderId);
        rs = ps.executeQuery();
        rs.first();
        int guildid = rs.getInt("guildid");
        rs.close();
        ps.close();
        return guildid;
    } catch (Exception e) {
        return 0;
    }
}
 
Example 15
Project: AeroStory   File: MapleStorage.java   View Source Code Vote up 5 votes
public static MapleStorage loadOrCreateFromDB(int id, int world) {
    MapleStorage ret = null;
    int storeId;
    try {
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT storageid, slots, meso FROM storages WHERE accountid = ? AND world = ?");
        ps.setInt(1, id);
        ps.setInt(2, world);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            return create(id, world);
        } else {
            storeId = rs.getInt("storageid");
            ret = new MapleStorage(storeId, (byte) rs.getInt("slots"), rs.getInt("meso"));
            rs.close();
            ps.close();
            for (Pair<Item, MapleInventoryType> item : ItemFactory.STORAGE.loadItems(ret.id, false)) {
                ret.items.add(item.getLeft());
            }
        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return ret;
}
 
Example 16
Project: uavstack   File: DAOFactory.java   View Source Code Vote up 5 votes
public Object getResult(ResultSet rs, String columnName) throws SQLException {

            int i = rs.getInt(columnName);
            if (rs.wasNull()) {
                return null;
            }
            else {
                return new Integer(i);
            }
        }
 
Example 17
Project: SistemaAlmoxarifado   File: ProdutoFornecedorDAO.java   View Source Code Vote up 5 votes
public static ProdutoFornecedor retreave(int id) throws SQLException {
    Statement stm
            = Database.createConnection().
                    createStatement();
    String sql = "SELECT * FROM produtos_fornecedores where id =" + id;
    ResultSet rs = stm.executeQuery(sql);
    rs.next();
    return new ProdutoFornecedor(id,
            rs.getInt("fornecedor"),
            rs.getInt("produto"));

}
 
Example 18
Project: parabuild-ci   File: IdentifierGeneratorFactory.java   View Source Code Vote up 5 votes
public static Serializable get(ResultSet rs, Type type, SessionImplementor session, Object owner) throws SQLException, IdentifierGenerationException {
	Class clazz = type.getReturnedClass();
	if ( clazz==Long.class ) {
		return new Long( rs.getLong(1) );
	}
	else if ( clazz==Integer.class ) {
		return new Integer( rs.getInt(1) );
	}
	else if ( clazz==Short.class ) {
		return new Short( rs.getShort(1) );
	}
	else {
		throw new IdentifierGenerationException("this id generator generates long, integer, short");
	}
}
 
Example 19
Project: MineDonate   File: UsersShops.java   View Source Code Vote up 4 votes
@Override
public void loadCategoryFromObject ( Object o ) {
	
	ResultSet rs = ( ResultSet ) o ;
	
    try {        	
    	
        while (rs.next()) {
        	
            final ShopInfo info = new ShopInfo(rs.getInt("id"), rs.getInt("id"), rs.getInt("rating"), rs.getString("UUID"), rs.getString("ownerName"), rs.getString("name"), rs.getBoolean("isFreezed"), rs.getString("freezer"), rs.getString("freezReason"), true, rs.getString("moneyType"));
            
            this.addMerch(info);
            
        }
        
    } catch (SQLException e) {
    	
        e.printStackTrace();
        
    }

    MineDonate . logInfo ( "Loaded " + m_Merch . size() + " merch in " + toString ( ) ) ;

}
 
Example 20
Project: plugin-bt-jira   File: JiraDao.java   View Source Code Vote up 3 votes
/**
 * Return a map where an entry is
 * <code>entry.key=reverseMap.value</code> and <code>entry.value=rs[resulsetPrefix+reverseMap.key]</code> if
 * <code>entry.value</code> is superior than 0.
 * 
 * @param reverseMap
 *            the set of results to read from the {@link ResultSet}. K of this map is used to extract the count.
 * @param rs
 *            the current {@link ResultSet}
 * @param resulsetPrefix
 *            Prefix of column name of result set.
 * @return K is the value of given reverse map. V is the non zero result column named with the following form :
 *         prefix+K of given reverse map.
 */
private Map<String, Integer> toMapCount(final Map<Integer, String> reverseMap, final ResultSet rs, final String resulsetPrefix)
		throws SQLException {
	final Map<String, Integer> result = new LinkedHashMap<>();
	for (final Entry<Integer, String> entry : reverseMap.entrySet()) {
		// Add only non zero values
		final int count = rs.getInt(resulsetPrefix + entry.getKey());
		if (count > 0) {
			result.put(entry.getValue(), count);
		}
	}
	return result;
}