	public void saveSummon(L2ServitorInstance summon)
	{
		if (summon == null || summon.getTimeRemaining() <= 0)
			return;
		_servitors.put(summon.getOwner().getObjectId(), summon.getReferenceSkill());

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(SAVE_SUMMON))
		{
			ps.setInt(1, summon.getOwner().getObjectId());
			ps.setInt(2, summon.getReferenceSkill());
			ps.setInt(3, (int) Math.round(summon.getCurrentHp()));
			ps.setInt(4, (int) Math.round(summon.getCurrentMp()));
			ps.setInt(5, summon.getTimeRemaining());
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Failed to store summon [SummonId: " + summon.getNpcId() + "] from Char [CharId: " + summon.getOwner().getObjectId() + "] data", e);
		}

	}

	public void saveSummon(L2ServitorInstance summon)
	{
		if (summon == null || summon.getTimeRemaining() <= 0)
			return;

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(SAVE_SUMMON);

			statement.setInt(1, summon.getOwner().getObjectId());
			statement.setInt(2, summon.getReferenceSkill());
			statement.setInt(3, (int) Math.round(summon.getCurrentHp()));
			statement.setInt(4, (int) Math.round(summon.getCurrentMp()));
			statement.setInt(5, summon.getTimeRemaining());

			statement.execute();
			statement.close();

			_servitors.put(summon.getOwner().getObjectId(), summon.getReferenceSkill());
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Failed to store summon [SummonId: " + summon.getNpcId() + "] from Char [CharId: " + summon.getOwner().getObjectId() + "] data", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(SAVE_SUMMON)) in method public saveSummon(summon L2ServitorInstance) : void from class com.l2jserver.gameserver.datatables.CharSummonTable


	public void restoreServitor(L2PcInstance activeChar)
	{
		int skillId = _servitors.get(activeChar.getObjectId());
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(LOAD_SUMMON))
		{
			ps.setInt(1, activeChar.getObjectId());
			ps.setInt(2, skillId);
			try (ResultSet rs = ps.executeQuery())
			{

				L2NpcTemplate summonTemplate;
				L2ServitorInstance summon;
				L2SkillSummon skill;

				while (rs.next())
				{
					int curHp = rs.getInt("curHp");
					int curMp = rs.getInt("curMp");
					int time = rs.getInt("time");

					skill = (L2SkillSummon) SkillTable.getInstance().getInfo(skillId, activeChar.getSkillLevel(skillId));
					if (skill == null)
					{
						removeServitor(activeChar);
						return;
					}

					summonTemplate = NpcTable.getInstance().getTemplate(skill.getNpcId());
					if (summonTemplate == null)
					{
						_log.warning("[CharSummonTable] Summon attemp for nonexisting Skill ID:" + skillId);
						return;
					}

					final int id = IdFactory.getInstance().getNextId();
					if (summonTemplate.isType("L2SiegeSummon"))
					{
						summon = new L2SiegeSummonInstance(id, summonTemplate, activeChar, skill);
					}
					else if (summonTemplate.isType("L2MerchantSummon"))
					{
						// TODO: Confirm L2Merchant summon = new L2MerchantSummonInstance(id, summonTemplate, activeChar, skill);
						summon = new L2ServitorInstance(id, summonTemplate, activeChar, skill);
					}
					else
					{
						summon = new L2ServitorInstance(id, summonTemplate, activeChar, skill);
					}

					summon.setName(summonTemplate.getName());
					summon.setTitle(activeChar.getName());
					summon.setExpPenalty(skill.getExpPenalty());
					summon.setSharedElementals(skill.getInheritElementals());
					summon.setSharedElementalsValue(skill.getElementalSharePercent());

					if (summon.getLevel() >= ExperienceTable.getInstance().getMaxPetLevel())
					{
						summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(ExperienceTable.getInstance().getMaxPetLevel()-1));
						_log.warning("Summon (" + summon.getName() + ") NpcID: " + summon.getNpcId() + " has a level above "+ExperienceTable.getInstance().getMaxPetLevel()+". Please rectify.");
					}
					else
					{
						summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(summon.getLevel() % ExperienceTable.getInstance().getMaxPetLevel()));
					}
					summon.setCurrentHp(curHp);
					summon.setCurrentMp(curMp);
					summon.setHeading(activeChar.getHeading());
					summon.setRunning();
					if (!(summon instanceof L2MerchantSummonInstance))
						activeChar.setPet(summon);

					summon.setTimeRemaining(time);

					//L2World.getInstance().storeObject(summon);
					summon.spawnMe(activeChar.getX() + 20, activeChar.getY() + 20, activeChar.getZ());
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "[CharSummonTable]: Summon cannot be restored: ", e);
		}
	}

	public void restoreServitor(L2PcInstance activeChar)
	{
		Connection con = null;
		try
		{
			int skillId = _servitors.get(activeChar.getObjectId());

			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(LOAD_SUMMON);
			statement.setInt(1, activeChar.getObjectId());
			statement.setInt(2, skillId);
			ResultSet rset = statement.executeQuery();

			L2NpcTemplate summonTemplate;
			L2ServitorInstance summon;
			L2SkillSummon skill;

			while (rset.next())
			{
				int curHp = rset.getInt("curHp");
				int curMp = rset.getInt("curMp");
				int time = rset.getInt("time");

				skill = (L2SkillSummon) SkillTable.getInstance().getInfo(skillId, activeChar.getSkillLevel(skillId));
				if (skill == null)
				{
					removeServitor(activeChar);
					return;
				}

				summonTemplate = NpcTable.getInstance().getTemplate(skill.getNpcId());
				if (summonTemplate == null)
				{
					_log.warning("[CharSummonTable] Summon attemp for nonexisting Skill ID:" + skillId);
					return;
				}

				final int id = IdFactory.getInstance().getNextId();
				if (summonTemplate.isType("L2SiegeSummon"))
				{
					summon = new L2SiegeSummonInstance(id, summonTemplate, activeChar, skill);
				}
				else if (summonTemplate.isType("L2MerchantSummon"))
				{
					// TODO: Confirm L2Merchant summon = new L2MerchantSummonInstance(id, summonTemplate, activeChar, skill);
					summon = new L2ServitorInstance(id, summonTemplate, activeChar, skill);
				}
				else
				{
					summon = new L2ServitorInstance(id, summonTemplate, activeChar, skill);
				}

				summon.setName(summonTemplate.getName());
				summon.setTitle(activeChar.getName());
				summon.setExpPenalty(skill.getExpPenalty());
				summon.setSharedElementals(skill.getInheritElementals());
				summon.setSharedElementalsValue(skill.getElementalSharePercent());

				if (summon.getLevel() >= ExperienceTable.getInstance().getMaxPetLevel())
				{
					summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(ExperienceTable.getInstance().getMaxPetLevel()-1));
					_log.warning("Summon (" + summon.getName() + ") NpcID: " + summon.getNpcId() + " has a level above "+ExperienceTable.getInstance().getMaxPetLevel()+". Please rectify.");
				}
				else
				{
					summon.getStat().setExp(ExperienceTable.getInstance().getExpForLevel(summon.getLevel() % ExperienceTable.getInstance().getMaxPetLevel()));
				}
				summon.setCurrentHp(curHp);
				summon.setCurrentMp(curMp);
				summon.setHeading(activeChar.getHeading());
				summon.setRunning();
				if (!(summon instanceof L2MerchantSummonInstance))
					activeChar.setPet(summon);

				summon.setTimeRemaining(time);

				//L2World.getInstance().storeObject(summon);
				summon.spawnMe(activeChar.getX() + 20, activeChar.getY() + 20, activeChar.getZ());
			}

			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "[CharSummonTable]: Summon cannot be restored: ", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(ResultSet rs=ps.executeQuery()) in method public restoreServitor(activeChar L2PcInstance) : void from class com.l2jserver.gameserver.datatables.CharSummonTable


	public void removeServitor(L2PcInstance activeChar)
	{
		_servitors.remove(activeChar.getObjectId());
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(REMOVE_SUMMON))
		{
			ps.setInt(1, activeChar.getObjectId());
			ps.execute();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "[CharSummonTable]: Summon cannot be removed: ", e);
		}
	}

	public void removeServitor(L2PcInstance activeChar)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(REMOVE_SUMMON);
			statement.setInt(1, activeChar.getObjectId());
			statement.execute();
			statement.close();
			_servitors.remove(activeChar.getObjectId());
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "[CharSummonTable]: Summon cannot be removed: ", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(REMOVE_SUMMON)) in method public removeServitor(activeChar L2PcInstance) : void from class com.l2jserver.gameserver.datatables.CharSummonTable


	protected CharTemplateTable()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement s = con.createStatement();
			ResultSet rset = s.executeQuery("SELECT * FROM char_templates, lvlupgain WHERE char_templates.classId = lvlupgain.classId ORDER BY char_templates.ClassId"))
		{
			StatsSet set;
			int cId;
			while (rset.next())
			{
				set = new StatsSet();
				cId = rset.getInt("ClassId");
				set.set("classId", cId);
				set.set("className", rset.getString("className"));
				set.set("raceId", rset.getInt("raceId"));
				set.set("baseSTR", rset.getInt("STR"));
				set.set("baseCON", rset.getInt("CON"));
				set.set("baseDEX", rset.getInt("DEX"));
				set.set("baseINT", rset.getInt("_INT"));
				set.set("baseWIT", rset.getInt("WIT"));
				set.set("baseMEN", rset.getInt("MEN"));
				set.set("baseHpMax", rset.getFloat("defaultHpBase"));
				set.set("lvlHpAdd", rset.getFloat("defaultHpAdd"));
				set.set("lvlHpMod", rset.getFloat("defaultHpMod"));
				set.set("baseMpMax", rset.getFloat("defaultMpBase"));
				set.set("baseCpMax", rset.getFloat("defaultCpBase"));
				set.set("lvlCpAdd", rset.getFloat("defaultCpAdd"));
				set.set("lvlCpMod", rset.getFloat("defaultCpMod"));
				set.set("lvlMpAdd", rset.getFloat("defaultMpAdd"));
				set.set("lvlMpMod", rset.getFloat("defaultMpMod"));
				set.set("baseHpReg", 2);
				set.set("baseMpReg", 0.9);
				set.set("basePAtk", rset.getInt("p_atk"));
				set.set("basePDef", rset.getInt("p_def"));
				set.set("baseMAtk", rset.getInt("m_atk"));
				set.set("baseMDef", rset.getInt("m_def"));
				set.set("classBaseLevel", rset.getInt("class_lvl"));
				set.set("baseRunSpd", rset.getInt("move_spd"));
				set.set("baseWalkSpd", 0);
				set.set("baseShldDef", 0);
				set.set("baseShldRate", 0);
				set.set("baseAtkRange", 40);

				set.set("spawnX", rset.getInt("x"));
				set.set("spawnY", rset.getInt("y"));
				set.set("spawnZ", rset.getInt("z"));

				set.set("collision_radius", rset.getDouble("m_col_r"));
				set.set("collision_height", rset.getDouble("m_col_h"));
				set.set("collision_radius_female", rset.getDouble("f_col_r"));
				set.set("collision_height_female", rset.getDouble("f_col_h"));

				final L2PcTemplate ct = new L2PcTemplate(set);
				_charTemplates.put(ClassId.getClassId(cId), ct);
			}
			_log.info("CharTemplateTable: Loaded " + _charTemplates.size() + " Character Templates.");
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "Failed loading char templates", e);
		}
	}

	protected CharTemplateTable()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			final PreparedStatement statement = con.prepareStatement("SELECT * FROM char_templates, lvlupgain WHERE char_templates.classId = lvlupgain.classId ORDER BY char_templates.ClassId");
			final ResultSet rset = statement.executeQuery();
			StatsSet set;
			int cId;
			while (rset.next())
			{
				set = new StatsSet();
				cId = rset.getInt("ClassId");
				set.set("classId", cId);
				set.set("className", rset.getString("className"));
				set.set("raceId", rset.getInt("raceId"));
				set.set("baseSTR", rset.getInt("STR"));
				set.set("baseCON", rset.getInt("CON"));
				set.set("baseDEX", rset.getInt("DEX"));
				set.set("baseINT", rset.getInt("_INT"));
				set.set("baseWIT", rset.getInt("WIT"));
				set.set("baseMEN", rset.getInt("MEN"));
				set.set("baseHpMax", rset.getFloat("defaultHpBase"));
				set.set("lvlHpAdd", rset.getFloat("defaultHpAdd"));
				set.set("lvlHpMod", rset.getFloat("defaultHpMod"));
				set.set("baseMpMax", rset.getFloat("defaultMpBase"));
				set.set("baseCpMax", rset.getFloat("defaultCpBase"));
				set.set("lvlCpAdd", rset.getFloat("defaultCpAdd"));
				set.set("lvlCpMod", rset.getFloat("defaultCpMod"));
				set.set("lvlMpAdd", rset.getFloat("defaultMpAdd"));
				set.set("lvlMpMod", rset.getFloat("defaultMpMod"));
				set.set("baseHpReg", 1.5);
				set.set("baseMpReg", 0.9);
				set.set("basePAtk", rset.getInt("p_atk"));
				set.set("basePDef", /* classId.isMage()? 77 : 129 */rset.getInt("p_def"));
				set.set("baseMAtk", rset.getInt("m_atk"));
				set.set("baseMDef", rset.getInt("char_templates.m_def"));
				set.set("classBaseLevel", rset.getInt("class_lvl"));
				set.set("basePAtkSpd", rset.getInt("p_spd"));
				set.set("baseMAtkSpd", /* classId.isMage()? 166 : 333 */rset.getInt("char_templates.m_spd"));
				set.set("baseCritRate", rset.getInt("char_templates.critical") / 10);
				set.set("baseRunSpd", rset.getInt("move_spd"));
				set.set("baseWalkSpd", 0);
				set.set("baseShldDef", 0);
				set.set("baseShldRate", 0);
				set.set("baseAtkRange", 40);

				set.set("spawnX", rset.getInt("x"));
				set.set("spawnY", rset.getInt("y"));
				set.set("spawnZ", rset.getInt("z"));

				set.set("collision_radius", rset.getDouble("m_col_r"));
				set.set("collision_height", rset.getDouble("m_col_h"));
				set.set("collision_radius_female", rset.getDouble("f_col_r"));
				set.set("collision_height_female", rset.getDouble("f_col_h"));

				final L2PcTemplate ct = new L2PcTemplate(set);
				_charTemplates.put(ClassId.getClassId(cId), ct);
			}
			rset.close();
			statement.close();
			_log.info("CharTemplateTable: Loaded " + _charTemplates.size() + " Character Templates.");
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "Failed loading char templates", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement s=con.createStatement(); ResultSet rset=s.executeQuery("SELECT * FROM char_templates, lvlupgain WHERE char_templates.classId = lvlupgain.classId ORDER BY char_templates.ClassId")) in method protected CharTemplateTable() from class com.l2jserver.gameserver.datatables.CharTemplateTable


	public synchronized void destroyClan(int clanId)
	{
		L2Clan clan = getClan(clanId);
		if (clan == null)
		{
			return;
		}

		clan.broadcastToOnlineMembers(SystemMessage.getSystemMessage(SystemMessageId.CLAN_HAS_DISPERSED));
		int castleId = clan.getCastleId();
		if (castleId == 0)
		{
			for (Siege siege : SiegeManager.getInstance().getSieges())
			{
				siege.removeSiegeClan(clan);
			}
		}
		int fortId = clan.getFortId();
		if (fortId == 0)
		{
			for (FortSiege siege : FortSiegeManager.getInstance().getSieges())
			{
				siege.removeSiegeClan(clan);
			}
		}
		int hallId = clan.getHideoutId();
		if(hallId == 0)
		{
			for(SiegableHall hall : CHSiegeManager.getInstance().getConquerableHalls().values())
				hall.removeAttacker(clan);
		}

		L2ClanMember leaderMember = clan.getLeader();
		if (leaderMember == null)
			clan.getWarehouse().destroyAllItems("ClanRemove", null, null);
		else
			clan.getWarehouse().destroyAllItems("ClanRemove", clan.getLeader().getPlayerInstance(), null);

		for (L2ClanMember member : clan.getMembers())
		{
			clan.removeClanMember(member.getObjectId(), 0);
		}

		_clans.remove(clanId);
		IdFactory.getInstance().releaseId(clanId);

		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			PreparedStatement statement = con.prepareStatement("DELETE FROM clan_data WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_privs WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_skills WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_subpledges WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? OR clan2=?");
			statement.setInt(1, clanId);
			statement.setInt(2, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_notices WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			if (castleId != 0)
			{
				statement = con.prepareStatement("UPDATE castle SET taxPercent = 0 WHERE id = ?");
				statement.setInt(1, castleId);
				statement.execute();
				statement.close();
			}
			if (fortId != 0)
			{
				Fort fort = FortManager.getInstance().getFortById(fortId);
				if (fort != null)
				{
					L2Clan owner = fort.getOwnerClan();
					if (clan == owner)
						fort.removeOwner(true);
				}
			}
			if(hallId != 0)
			{
				SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(hallId);
				if(hall != null && hall.getOwnerId() == clanId)
					hall.free();
			}
			if (Config.DEBUG)
				_log.fine("clan removed in db: " + clanId);
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error removing clan from DB.", e);
		}
	}

	public synchronized void destroyClan(int clanId)
	{
		L2Clan clan = getClan(clanId);
		if (clan == null)
		{
			return;
		}

		clan.broadcastToOnlineMembers(SystemMessage.getSystemMessage(SystemMessageId.CLAN_HAS_DISPERSED));
		int castleId = clan.getCastleId();
		if (castleId == 0)
		{
			for (Siege siege : SiegeManager.getInstance().getSieges())
			{
				siege.removeSiegeClan(clan);
			}
		}
		int fortId = clan.getFortId();
		if (fortId == 0)
		{
			for (FortSiege siege : FortSiegeManager.getInstance().getSieges())
			{
				siege.removeSiegeClan(clan);
			}
		}
		int hallId = clan.getHideoutId();
		if(hallId == 0)
		{
			for(SiegableHall hall : CHSiegeManager.getInstance().getConquerableHalls().values())
				hall.removeAttacker(clan);
		}

		L2ClanMember leaderMember = clan.getLeader();
		if (leaderMember == null)
			clan.getWarehouse().destroyAllItems("ClanRemove", null, null);
		else
			clan.getWarehouse().destroyAllItems("ClanRemove", clan.getLeader().getPlayerInstance(), null);

		for (L2ClanMember member : clan.getMembers())
		{
			clan.removeClanMember(member.getObjectId(), 0);
		}

		_clans.remove(clanId);
		IdFactory.getInstance().releaseId(clanId);

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM clan_data WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_privs WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_skills WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_subpledges WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? OR clan2=?");
			statement.setInt(1, clanId);
			statement.setInt(2, clanId);
			statement.execute();
			statement.close();

			statement = con.prepareStatement("DELETE FROM clan_notices WHERE clan_id=?");
			statement.setInt(1, clanId);
			statement.execute();
			statement.close();

			if (castleId != 0)
			{
				statement = con.prepareStatement("UPDATE castle SET taxPercent = 0 WHERE id = ?");
				statement.setInt(1, castleId);
				statement.execute();
				statement.close();
			}
			if (fortId != 0)
			{
				Fort fort = FortManager.getInstance().getFortById(fortId);
				if (fort != null)
				{
					L2Clan owner = fort.getOwnerClan();
					if (clan == owner)
						fort.removeOwner(true);
				}
			}
			if(hallId != 0)
			{
				SiegableHall hall = CHSiegeManager.getInstance().getSiegableHall(hallId);
				if(hall != null && hall.getOwnerId() == clanId)
					hall.free();
			}
			if (Config.DEBUG)
				_log.fine("clan removed in db: " + clanId);
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error removing clan from DB.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public destroyClan(clanId int) : void from class com.l2jserver.gameserver.datatables.ClanTable


	public void storeclanswars(int clanId1, int clanId2)
	{
		L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
		L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);

		if (!fireClanWarStartListeners(clan1, clan2))
		{
			return;
		}

		clan1.setEnemyClan(clan2);
		clan2.setAttackerClan(clan1);
		clan1.broadcastClanStatus();
		clan2.broadcastClanStatus();
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("REPLACE INTO clan_wars (clan1, clan2, wantspeace1, wantspeace2) VALUES(?,?,?,?)"))
		{
			ps.setInt(1, clanId1);
			ps.setInt(2, clanId2);
			ps.setInt(3, 0);
			ps.setInt(4, 0);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error storing clan wars data.", e);
		}

		//SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_BEGUN);
		//
		SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_WAR_DECLARED_AGAINST_S1_IF_KILLED_LOSE_LOW_EXP);
		msg.addString(clan2.getName());
		clan1.broadcastToOnlineMembers(msg);
		//msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_BEGUN);
		//msg.addString(clan1.getName());
		//clan2.broadcastToOnlineMembers(msg);
		// clan1 declared clan war.
		msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_S1_DECLARED_WAR);
		msg.addString(clan1.getName());
		clan2.broadcastToOnlineMembers(msg);
	}

	public void storeclanswars(int clanId1, int clanId2)
	{
		L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
		L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);

		if (!fireClanWarStartListeners(clan1, clan2))
		{
			return;
		}

		clan1.setEnemyClan(clan2);
		clan2.setAttackerClan(clan1);
		clan1.broadcastClanStatus();
		clan2.broadcastClanStatus();
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("REPLACE INTO clan_wars (clan1, clan2, wantspeace1, wantspeace2) VALUES(?,?,?,?)");
			statement.setInt(1, clanId1);
			statement.setInt(2, clanId2);
			statement.setInt(3, 0);
			statement.setInt(4, 0);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error storing clan wars data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		//SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_BEGUN);
		//
		SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_WAR_DECLARED_AGAINST_S1_IF_KILLED_LOSE_LOW_EXP);
		msg.addString(clan2.getName());
		clan1.broadcastToOnlineMembers(msg);
		//msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_BEGUN);
		//msg.addString(clan1.getName());
		//clan2.broadcastToOnlineMembers(msg);
		// clan1 declared clan war.
		msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_S1_DECLARED_WAR);
		msg.addString(clan1.getName());
		clan2.broadcastToOnlineMembers(msg);
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("REPLACE INTO clan_wars (clan1, clan2, wantspeace1, wantspeace2) VALUES(?,?,?,?)")) in method public storeclanswars(clanId1 int, clanId2 int) : void from class com.l2jserver.gameserver.datatables.ClanTable


	public void deleteclanswars(int clanId1, int clanId2)
	{
		L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
		L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);

		if (!fireClanWarEndListeners(clan1, clan2))
		{
			return;
		}

		clan1.deleteEnemyClan(clan2);
		clan2.deleteAttackerClan(clan1);
		clan1.broadcastClanStatus();
		clan2.broadcastClanStatus();
		//for(L2ClanMember player: clan1.getMembers())
		//{
		//	if(player.getPlayerInstance()!=null)
		//			player.getPlayerInstance().setWantsPeace(0);
		//}
		//for(L2ClanMember player: clan2.getMembers())
		//{
		//	if(player.getPlayerInstance()!=null)
		//			player.getPlayerInstance().setWantsPeace(0);
		//}

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?"))
		{
			ps.setInt(1, clanId1);
			ps.setInt(2, clanId2);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error removing clan wars data.", e);
		}

		//SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_ENDED);
		SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_AGAINST_S1_HAS_STOPPED);
		msg.addString(clan2.getName());
		clan1.broadcastToOnlineMembers(msg);
		msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_S1_HAS_DECIDED_TO_STOP);
		msg.addString(clan1.getName());
		clan2.broadcastToOnlineMembers(msg);
		//msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_ENDED);
		//msg.addString(clan1.getName());
		//clan2.broadcastToOnlineMembers(msg);
	}

	public void deleteclanswars(int clanId1, int clanId2)
	{
		L2Clan clan1 = ClanTable.getInstance().getClan(clanId1);
		L2Clan clan2 = ClanTable.getInstance().getClan(clanId2);

		if (!fireClanWarEndListeners(clan1, clan2))
		{
			return;
		}

		clan1.deleteEnemyClan(clan2);
		clan2.deleteAttackerClan(clan1);
		clan1.broadcastClanStatus();
		clan2.broadcastClanStatus();
		//for(L2ClanMember player: clan1.getMembers())
		//{
		//	if(player.getPlayerInstance()!=null)
		//			player.getPlayerInstance().setWantsPeace(0);
		//}
		//for(L2ClanMember player: clan2.getMembers())
		//{
		//	if(player.getPlayerInstance()!=null)
		//			player.getPlayerInstance().setWantsPeace(0);
		//}
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?");
			statement.setInt(1, clanId1);
			statement.setInt(2, clanId2);
			statement.execute();
			//statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?");
			//statement.setInt(1,clanId2);
			//statement.setInt(2,clanId1);
			//statement.execute();

			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error removing clan wars data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		//SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_ENDED);
		SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_AGAINST_S1_HAS_STOPPED);
		msg.addString(clan2.getName());
		clan1.broadcastToOnlineMembers(msg);
		msg = SystemMessage.getSystemMessage(SystemMessageId.CLAN_S1_HAS_DECIDED_TO_STOP);
		msg.addString(clan1.getName());
		clan2.broadcastToOnlineMembers(msg);
		//msg = SystemMessage.getSystemMessage(SystemMessageId.WAR_WITH_THE_S1_CLAN_HAS_ENDED);
		//msg.addString(clan1.getName());
		//clan2.broadcastToOnlineMembers(msg);
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? AND clan2=?")) in method public deleteclanswars(clanId1 int, clanId2 int) : void from class com.l2jserver.gameserver.datatables.ClanTable


	private void restorewars()
	{
		L2Clan clan1, clan2;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement statement = con.createStatement();
			ResultSet rset = statement.executeQuery("SELECT clan1, clan2 FROM clan_wars"))
		{
			while (rset.next())
			{
				clan1 = getClan(rset.getInt("clan1"));
				clan2 = getClan(rset.getInt("clan2"));
				if (clan1 != null && clan2 != null)
				{
					clan1.setEnemyClan(rset.getInt("clan2"));
					clan2.setAttackerClan(rset.getInt("clan1"));
				}
				else
					_log.log(Level.WARNING, "[ClanTable]: restorewars one of clans is null clan1:" + clan1 + " clan2:" + clan2);
			}
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error restoring clan wars data.", e);
		}
	}

	private void restorewars()
	{
		Connection con = null;
		L2Clan clan1, clan2;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT clan1, clan2 FROM clan_wars");
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{
				clan1 = getClan(rset.getInt("clan1"));
				clan2 = getClan(rset.getInt("clan2"));
				if (clan1 != null && clan2 != null)
				{
					clan1.setEnemyClan(rset.getInt("clan2"));
					clan2.setAttackerClan(rset.getInt("clan1"));
				}
				else
					_log.log(Level.WARNING, "[ClanTable]: restorewars one of clans is null clan1:" + clan1 + " clan2:" + clan2);
			}
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error restoring clan wars data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement statement=con.createStatement(); ResultSet rset=statement.executeQuery("SELECT clan1, clan2 FROM clan_wars")) in method private restorewars() : void from class com.l2jserver.gameserver.datatables.ClanTable


	private void restoreData()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT "
				+ L2DatabaseFactory.getInstance().safetyString(new String[] { "groupId", "itemId", "min", "max", "category", "chance" })
				+ " FROM herb_droplist_groups ORDER BY groupId, chance DESC");
			ResultSet dropData = statement.executeQuery())
		{
			L2DropData dropDat = null;
			while (dropData.next())
			{
				int groupId = dropData.getInt("groupId");
				FastList<L2DropCategory> category;
				if (_herbGroups.contains(groupId))
					category = _herbGroups.get(groupId);
				else
				{
					category = new FastList<>();
					_herbGroups.put(groupId, category);
				}

				dropDat = new L2DropData();

				dropDat.setItemId(dropData.getInt("itemId"));
				dropDat.setMinDrop(dropData.getInt("min"));
				dropDat.setMaxDrop(dropData.getInt("max"));
				dropDat.setChance(dropData.getInt("chance"));

				int categoryType = dropData.getInt("category");

				if (ItemTable.getInstance().getTemplate(dropDat.getItemId()) == null)
				{
					_log.warning("Herb Drop data for undefined item template! GroupId: " + groupId+" itemId: "+dropDat.getItemId());
					continue;
				}

				boolean catExists = false;
				for (L2DropCategory cat : category)
					// if the category exists, add the drop to this category.
					if (cat.getCategoryType() == categoryType)
					{
						cat.addDropData(dropDat, false);
						catExists = true;
						break;
					}
				// if the category doesn't exit, create it and add the drop
				if (!catExists)
				{
					L2DropCategory cat = new L2DropCategory(categoryType);
					cat.addDropData(dropDat, false);
					category.add(cat);
				}
			}
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "HerbDroplistGroupsTable: Error reading Herb dropdata. ", e);
		}
	}

	/**
	 *
	 */
	private void restoreData()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT "
					+ L2DatabaseFactory.getInstance().safetyString(new String[] { "groupId", "itemId", "min", "max", "category", "chance" })
					+ " FROM herb_droplist_groups ORDER BY groupId, chance DESC");
			ResultSet dropData = statement.executeQuery();
			L2DropData dropDat = null;

			while (dropData.next())
			{
				int groupId = dropData.getInt("groupId");
				FastList<L2DropCategory> category;
				if (_herbGroups.contains(groupId))
					category = _herbGroups.get(groupId);
				else
				{
					category = new FastList<>();
					_herbGroups.put(groupId, category);
				}

				dropDat = new L2DropData();

				dropDat.setItemId(dropData.getInt("itemId"));
				dropDat.setMinDrop(dropData.getInt("min"));
				dropDat.setMaxDrop(dropData.getInt("max"));
				dropDat.setChance(dropData.getInt("chance"));

				int categoryType = dropData.getInt("category");

				if (ItemTable.getInstance().getTemplate(dropDat.getItemId()) == null)
				{
					_log.warning("Herb Drop data for undefined item template! GroupId: " + groupId+" itemId: "+dropDat.getItemId());
					continue;
				}

				boolean catExists = false;
				for (L2DropCategory cat : category)
					// if the category exists, add the drop to this category.
					if (cat.getCategoryType() == categoryType)
					{
						cat.addDropData(dropDat, false);
						catExists = true;
						break;
					}
				// if the category doesn't exit, create it and add the drop
				if (!catExists)
				{
					L2DropCategory cat = new L2DropCategory(categoryType);
					cat.addDropData(dropDat, false);
					category.add(cat);
				}
			}

			dropData.close();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "HerbDroplistGroupsTable: Error reading Herb dropdata. ", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement("SELECT " + L2DatabaseFactory.getInstance().safetyString(new String[]{"groupId","itemId","min","max","category","chance"}) + " FROM herb_droplist_groups ORDER BY groupId, chance DESC"); ResultSet dropData=statement.executeQuery()) in method private restoreData() : void from class com.l2jserver.gameserver.datatables.HerbDropTable


/**
	 * Destroys the L2ItemInstance.

	 *
	 *  Actions :

	 *
Sets L2ItemInstance parameters to be unusable

	 *
Removes the L2ItemInstance object to _allObjects of L2world

	 *
Logs Item deletion according to log settings

	 * @param process a string identifier of process triggering this action.
	 * @param item the item instance to be destroyed.
	 * @param actor the player requesting the item destroy.
	 * @param reference the object referencing current action like NPC selling item or previous item in transformation.
	 */
	public void destroyItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
	{
		synchronized (item)
		{
			long old = item.getCount();
			item.setCount(0);
			item.setOwnerId(0);
			item.setLocation(ItemLocation.VOID);
			item.setLastChange(L2ItemInstance.REMOVED);

			L2World.getInstance().removeObject(item);
			IdFactory.getInstance().releaseId(item.getObjectId());

			if (Config.LOG_ITEMS)
			{
				if (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || item.getItemId() == ADENA_ID)))
				{
					LogRecord record = new LogRecord(Level.INFO, "DELETE:" + process);
					record.setLoggerName("item");
					record.setParameters(new Object[] { item, "PrevCount("+old+")", actor, reference });
					_logItems.log(record);
				}
			}

			if (actor != null)
			{
				if (actor.isGM())
				{
					String referenceName = "no-reference";
					if (reference instanceof L2Object)
					{
						referenceName = (((L2Object)reference).getName() != null?((L2Object)reference).getName():"no-name");
					}
					else if (reference instanceof String)
						referenceName = (String)reference;
					String targetName = (actor.getTarget() != null ? actor.getTarget().getName() : "no-target");
					if (Config.GMAUDIT)
						GMAudit.auditGMAction(actor.getName()+" ["+actor.getObjectId()+"]", process + "(id: " + item.getItemId() + " count: " + item.getCount()
								+ " itemObjId: " + item.getObjectId() + ")", targetName, "L2Object referencing this action is: "
								+ referenceName);
				}
			}

			// if it's a pet control item, delete the pet as well
			if (item.getItem().isPetItem())
			{
				try (Connection con = L2DatabaseFactory.getInstance().getConnection();
					PreparedStatement statement = con.prepareStatement("DELETE FROM pets WHERE item_obj_id=?"))
				{
					// Delete the pet in db
					statement.setInt(1, item.getObjectId());
					statement.execute();
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "could not delete pet objectid:", e);
				}
			}
		}
	}

/**
	 * Destroys the L2ItemInstance.

	 *
	 *  Actions :

	 *
Sets L2ItemInstance parameters to be unusable

	 *
Removes the L2ItemInstance object to _allObjects of L2world

	 *
Logs Item deletion according to log settings

	 * @param process a string identifier of process triggering this action.
	 * @param item the item instance to be destroyed.
	 * @param actor the player requesting the item destroy.
	 * @param reference the object referencing current action like NPC selling item or previous item in transformation.
	 */
	public void destroyItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
	{
		synchronized (item)
		{
			long old = item.getCount();
			item.setCount(0);
			item.setOwnerId(0);
			item.setLocation(ItemLocation.VOID);
			item.setLastChange(L2ItemInstance.REMOVED);

			L2World.getInstance().removeObject(item);
			IdFactory.getInstance().releaseId(item.getObjectId());

			if (Config.LOG_ITEMS)
			{
				if (!Config.LOG_ITEMS_SMALL_LOG || (Config.LOG_ITEMS_SMALL_LOG && (item.isEquipable() || item.getItemId() == ADENA_ID)))
				{
					LogRecord record = new LogRecord(Level.INFO, "DELETE:" + process);
					record.setLoggerName("item");
					record.setParameters(new Object[] { item, "PrevCount("+old+")", actor, reference });
					_logItems.log(record);
				}
			}

			if (actor != null)
			{
				if (actor.isGM())
				{
					String referenceName = "no-reference";
					if (reference instanceof L2Object)
					{
						referenceName = (((L2Object)reference).getName() != null?((L2Object)reference).getName():"no-name");
					}
					else if (reference instanceof String)
						referenceName = (String)reference;
					String targetName = (actor.getTarget() != null ? actor.getTarget().getName() : "no-target");
					if (Config.GMAUDIT)
						GMAudit.auditGMAction(actor.getName()+" ["+actor.getObjectId()+"]", process + "(id: " + item.getItemId() + " count: " + item.getCount()
								+ " itemObjId: " + item.getObjectId() + ")", targetName, "L2Object referencing this action is: "
								+ referenceName);
				}
			}

			// if it's a pet control item, delete the pet as well
			if (item.getItem().isPetItem())
			{
				Connection con = null;
				try
				{
					// Delete the pet in db
					con = L2DatabaseFactory.getInstance().getConnection();
					PreparedStatement statement = con.prepareStatement("DELETE FROM pets WHERE item_obj_id=?");
					statement.setInt(1, item.getObjectId());
					statement.execute();
					statement.close();
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "could not delete pet objectid:", e);
				}
				finally
				{
					L2DatabaseFactory.close(con);
				}
			}
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement("DELETE FROM pets WHERE item_obj_id=?")) in method public destroyItem(process String, item L2ItemInstance, actor L2PcInstance, reference Object) : void from class com.l2jserver.gameserver.datatables.ItemTable


	protected LevelUpData()
	{
		_lvlTable = new TIntObjectHashMap<>();
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement s = con.createStatement();
			ResultSet rs = s.executeQuery(SELECT_ALL))
		{
			L2LvlupData lvlDat;
			while (rs.next())
			{
				lvlDat = new L2LvlupData();
				lvlDat.setClassid(rs.getInt(CLASS_ID));
				lvlDat.setClassLvl(rs.getInt(CLASS_LVL));
				lvlDat.setClassHpBase(rs.getFloat(HP_BASE));
				lvlDat.setClassHpAdd(rs.getFloat(HP_ADD));
				lvlDat.setClassHpModifier(rs.getFloat(HP_MOD));
				lvlDat.setClassCpBase(rs.getFloat(CP_BASE));
				lvlDat.setClassCpAdd(rs.getFloat(CP_ADD));
				lvlDat.setClassCpModifier(rs.getFloat(CP_MOD));
				lvlDat.setClassMpBase(rs.getFloat(MP_BASE));
				lvlDat.setClassMpAdd(rs.getFloat(MP_ADD));
				lvlDat.setClassMpModifier(rs.getFloat(MP_MOD));

				_lvlTable.put(lvlDat.getClassid(), lvlDat);
			}
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error loading Level Up data.", e);
		}
		_log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates.");
	}

	protected LevelUpData()
	{
		_lvlTable = new TIntObjectHashMap<>();
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(SELECT_ALL);
			ResultSet rset = statement.executeQuery();
			L2LvlupData lvlDat;

			while (rset.next())
			{
				lvlDat = new L2LvlupData();
				lvlDat.setClassid(rset.getInt(CLASS_ID));
				lvlDat.setClassLvl(rset.getInt(CLASS_LVL));
				lvlDat.setClassHpBase(rset.getFloat(HP_BASE));
				lvlDat.setClassHpAdd(rset.getFloat(HP_ADD));
				lvlDat.setClassHpModifier(rset.getFloat(HP_MOD));
				lvlDat.setClassCpBase(rset.getFloat(CP_BASE));
				lvlDat.setClassCpAdd(rset.getFloat(CP_ADD));
				lvlDat.setClassCpModifier(rset.getFloat(CP_MOD));
				lvlDat.setClassMpBase(rset.getFloat(MP_BASE));
				lvlDat.setClassMpAdd(rset.getFloat(MP_ADD));
				lvlDat.setClassMpModifier(rset.getFloat(MP_MOD));

				_lvlTable.put(lvlDat.getClassid(), lvlDat);
			}

			rset.close();
			statement.close();

			_log.info("LevelUpData: Loaded " + _lvlTable.size() + " Character Level Up Templates.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "Error loading Level Up data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement s=con.createStatement(); ResultSet rs=s.executeQuery(SELECT_ALL)) in method protected LevelUpData() from class com.l2jserver.gameserver.datatables.LevelUpData


	protected NpcBufferTable()
	{
		int skillCount = 0;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement s = con.createStatement();
			ResultSet rset = s.executeQuery("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `npc_buffer` ORDER BY `npc_id` ASC"))
		{
			int lastNpcId = 0;
			NpcBufferSkills skills = null;

			while (rset.next())
			{
				int npcId = rset.getInt("npc_id");
				int skillId = rset.getInt("skill_id");
				int skillLevel = rset.getInt("skill_level");
				int skillFeeId = rset.getInt("skill_fee_id");
				int skillFeeAmount = rset.getInt("skill_fee_amount");
				int buffGroup = rset.getInt("buff_group");

				if (npcId != lastNpcId)
				{
					if (lastNpcId != 0)
					{
						_buffers.put(lastNpcId, skills);
					}

					skills = new NpcBufferSkills(npcId);
					skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
				}
				else if (skills != null)
				{
					skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
				}

				lastNpcId = npcId;
				skillCount++;
			}

			if (lastNpcId != 0)
			{
				_buffers.put(lastNpcId, skills);
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "NpcBufferTable: Error reading npc_buffer table: " + e.getMessage(), e);
		}

		if (Config.CUSTOM_NPCBUFFER_TABLES)
		{
			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
				Statement s = con.createStatement();
				ResultSet rset = s.executeQuery("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `custom_npc_buffer` ORDER BY `npc_id` ASC"))
			{
				int lastNpcId = 0;
				NpcBufferSkills skills = null;
				while (rset.next())
				{
					int npcId = rset.getInt("npc_id");
					int skillId = rset.getInt("skill_id");
					int skillLevel = rset.getInt("skill_level");
					int skillFeeId = rset.getInt("skill_fee_id");
					int skillFeeAmount = rset.getInt("skill_fee_amount");
					int buffGroup = rset.getInt("buff_group");

					if (npcId != lastNpcId)
					{
						if (lastNpcId != 0)
						{
							_buffers.put(lastNpcId, skills);
						}

						skills = new NpcBufferSkills(npcId);
						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
					}
					else if (skills != null)
					{
						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
					}
					lastNpcId = npcId;
					skillCount++;
				}

				if (lastNpcId != 0)
				{
					_buffers.put(lastNpcId, skills);
				}
			}
			catch (SQLException e)
			{
				_log.log(Level.SEVERE, "NpcBufferTable: Error reading custom_npc_buffer table: " + e.getMessage(), e);
			}
		}
		_log.info("NpcBufferSkillIdsTable: Loaded " + _buffers.size() + " buffers and " + skillCount + " skills.");
	}

	protected NpcBufferTable()
	{
		Connection con = null;
		int skillCount = 0;
		try
		{
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();

				PreparedStatement statement = con.prepareStatement("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `npc_buffer` ORDER BY `npc_id` ASC");
				ResultSet rset = statement.executeQuery();

				int lastNpcId = 0;
				NpcBufferSkills skills = null;

				while (rset.next())
				{
					int npcId = rset.getInt("npc_id");
					int skillId = rset.getInt("skill_id");
					int skillLevel = rset.getInt("skill_level");
					int skillFeeId = rset.getInt("skill_fee_id");
					int skillFeeAmount = rset.getInt("skill_fee_amount");
					int buffGroup = rset.getInt("buff_group");

					if (npcId != lastNpcId)
					{
						if (lastNpcId != 0)
						{
							_buffers.put(lastNpcId, skills);
						}

						skills = new NpcBufferSkills(npcId);
						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
					}
					else if (skills != null)
					{
						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
					}

					lastNpcId = npcId;
					skillCount++;
				}

				if (lastNpcId != 0)
				{
					_buffers.put(lastNpcId, skills);
				}
				rset.close();
				statement.close();
			}
			catch (Exception e)
			{
				_log.log(Level.SEVERE, "NpcBufferTable: Error reading npc_buffer table: " + e.getMessage(), e);
			}

			if (Config.CUSTOM_NPCBUFFER_TABLES)
			{
				try
				{
					if (con == null)
					{
						con = L2DatabaseFactory.getInstance().getConnection();
					}
					PreparedStatement statement = con.prepareStatement("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `custom_npc_buffer` ORDER BY `npc_id` ASC");
					ResultSet rset = statement.executeQuery();

					int lastNpcId = 0;
					NpcBufferSkills skills = null;

					while (rset.next())
					{
						int npcId = rset.getInt("npc_id");
						int skillId = rset.getInt("skill_id");
						int skillLevel = rset.getInt("skill_level");
						int skillFeeId = rset.getInt("skill_fee_id");
						int skillFeeAmount = rset.getInt("skill_fee_amount");
						int buffGroup = rset.getInt("buff_group");

						if (npcId != lastNpcId)
						{
							if (lastNpcId != 0)
							{
								_buffers.put(lastNpcId, skills);
							}

							skills = new NpcBufferSkills(npcId);
							skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
						}
						else if (skills != null)
						{
							skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
						}
						lastNpcId = npcId;
						skillCount++;
					}

					if (lastNpcId != 0)
					{
						_buffers.put(lastNpcId, skills);
					}
					rset.close();
					statement.close();
				}
				catch (Exception e)
				{
					_log.log(Level.SEVERE, "NpcBufferTable: Error reading custom_npc_buffer table: " + e.getMessage(), e);
				}
			}
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		_log.info("NpcBufferSkillIdsTable: Loaded " + _buffers.size() + " buffers and " + skillCount + " skills.");
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement s=con.createStatement(); ResultSet rset=s.executeQuery("SELECT `npc_id`,`skill_id`,`skill_level`,`skill_fee_id`,`skill_fee_amount`,`buff_group` FROM `npc_buffer` ORDER BY `npc_id` ASC")) in method protected NpcBufferTable() from class com.l2jserver.gameserver.datatables.NpcBufferTable


	/**
	 * Save npc.
	 * @param npc the npc
	 */
	public void saveNpc(StatsSet npc)
	{
		final Map<String, Object> set = npc.getSet();
		int length = 0;
		for (Object obj : set.keySet())
		{
			// 15 is just guessed npc name length
			length += ((String) obj).length() + 7 + 15;
		}

		final StringBuilder npcSb = new StringBuilder(length);
		final StringBuilder npcAiSb = new StringBuilder(30);
		String attribute;
		String value;
		for (Entry<String, Object> entry : set.entrySet())
		{
			attribute = entry.getKey();
			value = String.valueOf(entry.getValue());
			switch (attribute)
			{
				case "npcId":
					break;
				case "aggro":
				case "showName":
				case "targetable":
				{
					appendEntry(npcAiSb, attribute, value);
					break;
				}
				default:
				{
					appendEntry(npcSb, attribute, value);
				}
			}
		}

		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int updated = 0;
			final int npcId = npc.getInteger("npcId");
			if (Config.CUSTOM_NPC_TABLE)
			{
				updated = performUpdate(npcSb, "custom_npc", "id", npcId, con);
				performUpdate(npcAiSb, "custom_npcaidata", "npcId", npcId, con);
			}

			if (updated == 0)
			{
				performUpdate(npcSb, "npc", "id", npcId, con);
				performUpdate(npcAiSb, "npcaidata", "npcId", npcId, con);
			}
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not store new NPC data in database: " + e.getMessage(), e);
		}
	}

	/**
	 * @param npc
	 */
	public void saveNpc(StatsSet npc)
	{
		final Map<String, Object> set = npc.getSet();
		int length = 0;
		for (Object obj : set.keySet())
		{
			// 15 is just guessed npc name length
			length += ((String) obj).length() + 7 + 15;
		}

		final StringBuilder npcSb = new StringBuilder(length);
		final StringBuilder npcAiSb = new StringBuilder(30);
		String attribute;
		String value;
		for (Entry<String, Object> entry : set.entrySet())
		{
			attribute = entry.getKey();
			value = String.valueOf(entry.getValue());
			switch (attribute)
			{
				case "npcId":
					break;
				case "aggro":
				case "showName":
				case "targetable":
				{
					appendEntry(npcAiSb, attribute, value);
					break;
				}
				default:
				{
					appendEntry(npcSb, attribute, value);
				}
			}
		}

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			int updated = 0;
			final int npcId = npc.getInteger("npcId");
			if (Config.CUSTOM_NPC_TABLE)
			{
				updated = performUpdate(npcSb, "custom_npc", "id", npcId, con);
				performUpdate(npcAiSb, "custom_npcaidata", "npcId", npcId, con);
			}

			if (updated == 0)
			{
				performUpdate(npcSb, "npc", "id", npcId, con);
				performUpdate(npcAiSb, "npcaidata", "npcId", npcId, con);
			}
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not store new NPC data in database: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public saveNpc(npc StatsSet) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Load npcs.
	 * @param id the id
	 */
	public void loadNpcs(int id)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int count = loadNpcs(con, id, false);
			int ccount = 0;
			if (Config.CUSTOM_NPC_TABLE)
			{
				ccount = loadNpcs(con, id, true);
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " (Custom: " + ccount + ") NPC template(s).");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load.
	 */
	public void loadNpcs(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement;
			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM npc WHERE id = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM npc ORDER BY id");
			}
			ResultSet rset = statement.executeQuery();

			int cont = 0;
			int cCont = 0;

			while (rset.next())
			{
				fillNpcTable(rset);
				cont++;
			}

			rset.close();
			statement.close();

			if (Config.CUSTOM_NPC_TABLE)
			{
				if (id > 0)
				{
					statement = con.prepareStatement("SELECT * FROM custom_npc WHERE id = ?");
					statement.setInt(1, id);
				}
				else
				{
					statement = con.prepareStatement("SELECT * FROM custom_npc ORDER BY id");
				}
				rset = statement.executeQuery();

				while (rset.next())
				{
					fillNpcTable(rset);
					cCont++;
				}

				rset.close();
				statement.close();
			}

			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " (Custom: " + cCont + ") NPC template(s).");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error creating NPC table.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public loadNpcs(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's skills.
	 */
	public void loadNpcsSkills(int id)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int count = loadNpcsSkills(con, id, false);
			int ccount = 0;
			if (Config.CUSTOM_NPC_SKILLS_TABLE)
			{
				ccount = loadNpcsSkills(con, id, true);
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " (Custom: " + ccount + ") NPC skills.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's skills.
	 */
	public void loadNpcsSkills(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement;
			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM npcskills WHERE npcid = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM npcskills ORDER BY npcid");
			}

			ResultSet rset = statement.executeQuery();

			int cont = 0;
			int cCont = 0;

			L2NpcTemplate npcDat = null;
			L2Skill npcSkill = null;

			while (rset.next())
			{
				int mobId = rset.getInt("npcid");
				npcDat = _npcs.get(mobId);

				if (npcDat == null)
				{
					_log.warning(getClass().getSimpleName() + ": Skill data for undefined NPC. npcId: " + mobId);
					continue;
				}

				int skillId = rset.getInt("skillid");
				int level = rset.getInt("level");

				if (skillId == L2Skill.SKILL_NPC_RACE)
				{
					npcDat.setRace(level);
					continue;
				}

				npcSkill = SkillTable.getInstance().getInfo(skillId, level);
				if (npcSkill == null)
				{
					continue;
				}
				cont++;
				npcDat.addSkill(npcSkill);
			}

			rset.close();
			statement.close();

			if (Config.CUSTOM_NPC_SKILLS_TABLE)
			{
				if (id > 0)
				{
					statement = con.prepareStatement("SELECT * FROM custom_npcskills WHERE npcid = ?");
					statement.setInt(1, id);
				}
				else
				{
					statement = con.prepareStatement("SELECT * FROM custom_npcskills ORDER BY npcid");
				}
				rset = statement.executeQuery();

				while (rset.next())
				{
					int mobId = rset.getInt("npcid");
					npcDat = _npcs.get(mobId);

					if (npcDat == null)
					{
						_log.warning("Custom " + getClass().getSimpleName() + ": Skill data for undefined NPC. npcId: " + mobId);
						continue;
					}

					int skillId = rset.getInt("skillid");
					int level = rset.getInt("level");

					if ((npcDat.getRace() == null) && (skillId == L2Skill.SKILL_NPC_RACE))
					{
						npcDat.setRace(level);
						continue;
					}

					npcSkill = SkillTable.getInstance().getInfo(skillId, level);

					if (npcSkill == null)
					{
						continue;
					}

					cCont++;
					npcDat.addSkill(npcSkill);
				}

				rset.close();
				statement.close();
			}

			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " (Custom: " + cCont + ") npc skills.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC skills table.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public loadNpcsSkills(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's drops.
	 */
	public void loadNpcsDrop(int id)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int count = loadNpcsDrop(con, id, false);
			int ccount = 0;
			if (Config.CUSTOM_DROPLIST_TABLE)
			{
				ccount = loadNpcsDrop(con, id, true);
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " (Custom: " + ccount + ") drops.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's drops.
	 */
	public void loadNpcsDrop(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = null;

			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM droplist WHERE mobId = ? ORDER BY mobId, chance DESC");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM droplist ORDER BY mobId, chance DESC");
			}

			ResultSet rset = statement.executeQuery();
			L2DropData dropDat = null;
			L2NpcTemplate npcDat = null;

			int cont = 0;
			int cCont = 0;

			while (rset.next())
			{
				int mobId = rset.getInt("mobId");
				npcDat = _npcs.get(mobId);
				if (npcDat == null)
				{
					_log.warning(getClass().getSimpleName() + ": Drop data for undefined NPC. npcId: " + mobId);
					continue;
				}
				dropDat = new L2DropData();

				dropDat.setItemId(rset.getInt("itemId"));
				dropDat.setMinDrop(rset.getInt("min"));
				dropDat.setMaxDrop(rset.getInt("max"));
				dropDat.setChance(rset.getInt("chance"));

				int category = rset.getInt("category");

				if (ItemTable.getInstance().getTemplate(dropDat.getItemId()) == null)
				{
					_log.warning(getClass().getSimpleName() + ": Drop data for undefined item template! NpcId: " + mobId + " itemId: " + dropDat.getItemId());
					continue;
				}
				cont++;
				npcDat.addDropData(dropDat, category);
			}

			rset.close();
			statement.close();

			if (Config.CUSTOM_DROPLIST_TABLE)
			{
				if (id > 0)
				{
					statement = con.prepareStatement("SELECT * FROM custom_droplist WHERE mobId = ? ORDER BY mobId, chance DESC");
					statement.setInt(1, id);
				}
				else
				{
					statement = con.prepareStatement("SELECT * FROM custom_droplist ORDER BY mobId, chance DESC");
				}

				rset = statement.executeQuery();
				int mobId;
				int category;
				while (rset.next())
				{
					mobId = rset.getInt("mobId");
					npcDat = _npcs.get(mobId);
					if (npcDat == null)
					{
						_log.warning(getClass().getSimpleName() + ": CUSTOM DROPLIST: Drop data for undefined NPC. npcId: " + mobId);
						continue;
					}

					dropDat = new L2DropData();
					dropDat.setItemId(rset.getInt("itemId"));
					dropDat.setMinDrop(rset.getInt("min"));
					dropDat.setMaxDrop(rset.getInt("max"));
					dropDat.setChance(rset.getInt("chance"));
					category = rset.getInt("category");

					if (ItemTable.getInstance().getTemplate(dropDat.getItemId()) == null)
					{
						_log.warning(getClass().getSimpleName() + ": Custom drop data for undefined item template! NpcId: " + mobId + " itemId: " + dropDat.getItemId());
						continue;
					}

					npcDat.addDropData(dropDat, category);
					cCont++;
				}
				rset.close();
				statement.close();
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " (Custom: " + cCont + ") drops.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC dropdata. ", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public loadNpcsDrop(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's skill learn list.
	 */
	private void loadNpcsSkillLearn(int id)
	{
		final String query = (id > 0) ? SELECT_SKILL_LEARN_BY_ID : SELECT_SKILL_LEARN_ALL;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(query))
		{
			if (id > 0)
			{
				statement.setInt(1, id);
			}

			int count = 0;
			try (ResultSet rs = statement.executeQuery())
			{
				int npcId;
				int classId;
				L2NpcTemplate npc;
				while (rs.next())
				{
					npcId = rs.getInt("npc_id");
					classId = rs.getInt("class_id");
					npc = getTemplate(npcId);
					if (npc == null)
					{
						_log.warning(getClass().getSimpleName() + ": Error getting NPC template ID " + npcId + " while trying to load skill trainer data.");
						continue;
					}

					count++;
					npc.addTeachInfo(ClassId.getClassId(classId));
				}
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " Skill Learn.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC trainer data.", e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's skill learn list.
	 */
	private void loadNpcsSkillLearn(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement;
			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM skill_learn WHERE npc_id = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM skill_learn");
			}

			ResultSet rset = statement.executeQuery();

			int cont = 0;
			int npcId;
			int classId;
			L2NpcTemplate npc;
			while (rset.next())
			{
				npcId = rset.getInt("npc_id");
				classId = rset.getInt("class_id");
				npc = getTemplate(npcId);
				if (npc == null)
				{
					_log.warning(getClass().getSimpleName() + ": Error getting NPC template ID " + npcId + " while trying to load skill trainer data.");
					continue;
				}

				cont++;
				npc.addTeachInfo(ClassId.getClassId(classId));
			}

			rset.close();
			statement.close();

			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " Skill Learn.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC trainer data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(ResultSet rs=statement.executeQuery()) in method private loadNpcsSkillLearn(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's minions.
	 */
	public void loadMinions(int id)
	{
		final String query = (id > 0) ? SELECT_MINION_BY_ID : SELECT_MINION_ALL;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(query))
		{
			if (id > 0)
			{
				statement.setInt(1, id);
			}

			int count = 0;
			try (ResultSet rset = statement.executeQuery())
			{
				L2MinionData minionDat = null;
				L2NpcTemplate npcDat = null;

				int raidId;
				while (rset.next())
				{
					raidId = rset.getInt("boss_id");
					npcDat = _npcs.get(raidId);
					if (npcDat == null)
					{
						_log.warning(getClass().getSimpleName() + ": Minion references undefined boss NPC. Boss NpcId: " + raidId);
						continue;
					}

					minionDat = new L2MinionData();
					minionDat.setMinionId(rset.getInt("minion_id"));
					minionDat.setAmountMin(rset.getInt("amount_min"));
					minionDat.setAmountMax(rset.getInt("amount_max"));
					npcDat.addRaidData(minionDat);
					count++;
				}
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " Minions.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading minion data.", e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's minions.
	 */
	public void loadMinions(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = null;

			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM minions WHERE boss_id = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM minions ORDER BY boss_id");
			}

			ResultSet rset = statement.executeQuery();

			L2MinionData minionDat = null;
			L2NpcTemplate npcDat = null;
			int cnt = 0;
			int raidId;
			while (rset.next())
			{
				raidId = rset.getInt("boss_id");
				npcDat = _npcs.get(raidId);
				if (npcDat == null)
				{
					_log.warning(getClass().getSimpleName() + ": Minion references undefined boss NPC. Boss NpcId: " + raidId);
					continue;
				}

				minionDat = new L2MinionData();
				minionDat.setMinionId(rset.getInt("minion_id"));
				minionDat.setAmountMin(rset.getInt("amount_min"));
				minionDat.setAmountMax(rset.getInt("amount_max"));
				npcDat.addRaidData(minionDat);
				cnt++;
			}

			rset.close();
			statement.close();
			_log.info(getClass().getSimpleName() + ": Loaded " + cnt + " Minions.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading minion data.", e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(ResultSet rset=statement.executeQuery()) in method public loadMinions(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's AI data.
	 */
	public void loadNpcsAI(int id)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int count = loadNpcAi(con, id, false);
			int ccount = 0;
			if (Config.CUSTOM_NPC_TABLE)
			{
				ccount = loadNpcAi(con, id, true);
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " (Custom: " + ccount + ") AI Data.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's AI data.
	 */
	public void loadNpcsAI(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = null;

			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM npcaidata WHERE npcId = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM npcaidata ORDER BY npcId");
			}

			ResultSet rset = statement.executeQuery();

			L2NpcAIData npcAIDat = null;
			L2NpcTemplate npcDat = null;

			int cont = 0;
			int cCont = 0;
			int npcId;
			while (rset.next())
			{
				npcId = rset.getInt("npcId");
				npcDat = _npcs.get(npcId);
				if (npcDat == null)
				{
					_log.severe(getClass().getSimpleName() + ": AI Data Error with id : " + npcId);
					continue;
				}
				npcAIDat = new L2NpcAIData();

				npcAIDat.setPrimarySkillId(rset.getInt("primarySkillId"));
				npcAIDat.setMinSkillChance(rset.getInt("minSkillChance"));
				npcAIDat.setMaxSkillChance(rset.getInt("maxSkillChance"));
				npcAIDat.setAggro(rset.getInt("aggro"));
				npcAIDat.setCanMove(rset.getInt("canMove"));
				npcAIDat.setShowName(rset.getBoolean("showName"));
				npcAIDat.setTargetable(rset.getBoolean("targetable"));
				npcAIDat.setSoulShot(rset.getInt("soulshot"));
				npcAIDat.setSpiritShot(rset.getInt("spiritshot"));
				npcAIDat.setSoulShotChance(rset.getInt("ssChance"));
				npcAIDat.setSpiritShotChance(rset.getInt("spsChance"));
				npcAIDat.setIsChaos(rset.getInt("isChaos"));
				npcAIDat.setShortRangeSkill(rset.getInt("minRangeSkill"));
				npcAIDat.setShortRangeChance(rset.getInt("minRangeChance"));
				npcAIDat.setLongRangeSkill(rset.getInt("maxRangeSkill"));
				npcAIDat.setLongRangeChance(rset.getInt("maxRangeChance"));
				npcAIDat.setClan(rset.getString("clan"));
				npcAIDat.setClanRange(rset.getInt("clanRange"));
				npcAIDat.setEnemyClan(rset.getString("enemyClan"));
				npcAIDat.setEnemyRange(rset.getInt("enemyRange"));
				npcAIDat.setDodge(rset.getInt("dodge"));
				npcAIDat.setAi(rset.getString("aiType"));

				npcDat.setAIData(npcAIDat);
				cont++;
			}

			rset.close();
			statement.close();

			if (Config.CUSTOM_NPC_TABLE)
			{
				if (id > 0)
				{
					statement = con.prepareStatement("SELECT * FROM custom_npcaidata WHERE npcId = ?");
					statement.setInt(1, id);
				}
				else
				{
					statement = con.prepareStatement("SELECT * FROM custom_npcaidata ORDER BY npcId");
				}

				rset = statement.executeQuery();
				while (rset.next())
				{
					npcId = rset.getInt("npcId");
					npcDat = _npcs.get(npcId);
					if (npcDat == null)
					{
						_log.severe(getClass().getSimpleName() + ": Custom AI Data Error with id : " + npcId);
						continue;
					}
					npcAIDat = new L2NpcAIData();

					npcAIDat.setPrimarySkillId(rset.getInt("primarySkillId"));
					npcAIDat.setMinSkillChance(rset.getInt("minSkillChance"));
					npcAIDat.setMaxSkillChance(rset.getInt("maxSkillChance"));
					npcAIDat.setAggro(rset.getInt("aggro"));
					npcAIDat.setCanMove(rset.getInt("canMove"));
					npcAIDat.setShowName(rset.getBoolean("showName"));
					npcAIDat.setTargetable(rset.getBoolean("targetable"));
					npcAIDat.setSoulShot(rset.getInt("soulshot"));
					npcAIDat.setSpiritShot(rset.getInt("spiritshot"));
					npcAIDat.setSoulShotChance(rset.getInt("ssChance"));
					npcAIDat.setSpiritShotChance(rset.getInt("spsChance"));
					npcAIDat.setIsChaos(rset.getInt("isChaos"));
					npcAIDat.setShortRangeSkill(rset.getInt("minRangeSkill"));
					npcAIDat.setShortRangeChance(rset.getInt("minRangeChance"));
					npcAIDat.setLongRangeSkill(rset.getInt("maxRangeSkill"));
					npcAIDat.setLongRangeChance(rset.getInt("maxRangeChance"));
					npcAIDat.setClan(rset.getString("clan"));
					npcAIDat.setClanRange(rset.getInt("clanRange"));
					npcAIDat.setEnemyClan(rset.getString("enemyClan"));
					npcAIDat.setEnemyRange(rset.getInt("enemyRange"));
					npcAIDat.setDodge(rset.getInt("dodge"));
					npcAIDat.setAi(rset.getString("aiType"));

					npcDat.setAIData(npcAIDat);
					cCont++;
				}

				rset.close();
				statement.close();
			}

			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " (Custom: " + cCont + ") AI Data.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public loadNpcsAI(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's element data.
	 */
	public void loadNpcsElement(int id)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
		{
			int count = loadNpcsElement(con, id, false);
			int ccount = 0;
			if (Config.CUSTOM_NPC_TABLE)
			{
				ccount = loadNpcsElement(con, id, true);
			}
			_log.info(getClass().getSimpleName() + ": Loaded " + count + " (Custom: " + ccount + ") Elementals Data.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC AI Data: " + e.getMessage(), e);
		}
	}

	/**
	 * Id equals to zero or lesser means all.
	 * @param id of the NPC to load it's element data.
	 */
	public void loadNpcsElement(int id)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = null;
			if (id > 0)
			{
				statement = con.prepareStatement("SELECT * FROM npc_elementals WHERE npc_id = ?");
				statement.setInt(1, id);
			}
			else
			{
				statement = con.prepareStatement("SELECT * FROM npc_elementals ORDER BY npc_id");
			}

			ResultSet rset = statement.executeQuery();
			L2NpcTemplate npcDat = null;

			int cont = 0;
			int cCount = 0;
			int npcId;
			while (rset.next())
			{
				npcId = rset.getInt("npc_id");
				npcDat = _npcs.get(npcId);
				if (npcDat == null)
				{
					_log.severe("NPCElementals: Elementals Error with id : " + npcId);
					continue;
				}
				switch (rset.getByte("elemAtkType"))
				{
					case Elementals.FIRE:
						npcDat.setBaseFire(rset.getInt("elemAtkValue"));
						break;
					case Elementals.WATER:
						npcDat.setBaseWater(rset.getInt("elemAtkValue"));
						break;
					case Elementals.EARTH:
						npcDat.setBaseEarth(rset.getInt("elemAtkValue"));
						break;
					case Elementals.WIND:
						npcDat.setBaseWind(rset.getInt("elemAtkValue"));
						break;
					case Elementals.HOLY:
						npcDat.setBaseHoly(rset.getInt("elemAtkValue"));
						break;
					case Elementals.DARK:
						npcDat.setBaseDark(rset.getInt("elemAtkValue"));
						break;
					default:
						_log.severe("NPCElementals: Elementals Error with id : " + npcId + "; unknown elementType: " + rset.getByte("elemAtkType"));
						continue;
				}
				npcDat.setBaseFireRes(rset.getInt("fireDefValue"));
				npcDat.setBaseWaterRes(rset.getInt("waterDefValue"));
				npcDat.setBaseEarthRes(rset.getInt("earthDefValue"));
				npcDat.setBaseWindRes(rset.getInt("windDefValue"));
				npcDat.setBaseHolyRes(rset.getInt("holyDefValue"));
				npcDat.setBaseDarkRes(rset.getInt("darkDefValue"));
				cont++;
			}

			rset.close();
			statement.close();

			if (Config.CUSTOM_NPC_TABLE)
			{
				if (id > 0)
				{
					statement = con.prepareStatement("SELECT * FROM custom_npc_elementals WHERE npc_id = ?");
					statement.setInt(1, id);
				}
				else
				{
					statement = con.prepareStatement("SELECT * FROM custom_npc_elementals ORDER BY npc_id");
				}

				rset = statement.executeQuery();

				while (rset.next())
				{
					npcId = rset.getInt("npc_id");
					npcDat = _npcs.get(npcId);
					if (npcDat == null)
					{
						_log.severe("NPCElementals: Custom Elementals Error with id : " + npcId);
						continue;
					}
					switch (rset.getByte("elemAtkType"))
					{
						case Elementals.FIRE:
							npcDat.setBaseFire(rset.getInt("elemAtkValue"));
							break;
						case Elementals.WATER:
							npcDat.setBaseWater(rset.getInt("elemAtkValue"));
							break;
						case Elementals.EARTH:
							npcDat.setBaseEarth(rset.getInt("elemAtkValue"));
							break;
						case Elementals.WIND:
							npcDat.setBaseWind(rset.getInt("elemAtkValue"));
							break;
						case Elementals.HOLY:
							npcDat.setBaseHoly(rset.getInt("elemAtkValue"));
							break;
						case Elementals.DARK:
							npcDat.setBaseDark(rset.getInt("elemAtkValue"));
							break;
						default:
							_log.severe("NPCElementals: Custom Elementals Error with id : " + npcId + "; unknown elementType: " + rset.getByte("elemAtkType"));
							continue;
					}
					npcDat.setBaseFireRes(rset.getInt("fireDefValue"));
					npcDat.setBaseWaterRes(rset.getInt("waterDefValue"));
					npcDat.setBaseEarthRes(rset.getInt("earthDefValue"));
					npcDat.setBaseWindRes(rset.getInt("windDefValue"));
					npcDat.setBaseHolyRes(rset.getInt("holyDefValue"));
					npcDat.setBaseDarkRes(rset.getInt("darkDefValue"));
					cont++;
				}
				rset.close();
				statement.close();
			}

			_log.info(getClass().getSimpleName() + ": Loaded " + cont + " (Custom: " + cCount + ") elementals Data.");
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC Elementals Data: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection()) in method public loadNpcsElement(id int) : void from class com.l2jserver.gameserver.datatables.NpcTable


	public static void storeOffliners()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement stm1 = con.prepareStatement(CLEAR_OFFLINE_TABLE);
			PreparedStatement stm2 = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS);
			PreparedStatement stm3 = con.prepareStatement(SAVE_OFFLINE_STATUS);
			PreparedStatement stm_items = con.prepareStatement(SAVE_ITEMS))
		{
			stm1.execute();
			stm2.execute();
			con.setAutoCommit(false); // avoid halfway done

			//TextBuilder items = TextBuilder.newInstance();
			for (L2PcInstance pc : L2World.getInstance().getAllPlayersArray())
			{
				try
				{
					if ((pc.getPrivateStoreType() != L2PcInstance.STORE_PRIVATE_NONE) && (pc.getClient() == null || pc.getClient().isDetached()))
					{
						stm3.setInt(1, pc.getObjectId()); //Char Id
						stm3.setLong(2, pc.getOfflineStartTime());
						stm3.setInt(3, pc.getPrivateStoreType()); //store type
						String title = null;

						switch (pc.getPrivateStoreType())
						{
							case L2PcInstance.STORE_PRIVATE_BUY:
								if (!Config.OFFLINE_TRADE_ENABLE)
									continue;
								title = pc.getBuyList().getTitle();
								for (TradeItem i : pc.getBuyList().getItems())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getItem().getItemId());
									stm_items.setLong(3, i.getCount());
									stm_items.setLong(4, i.getPrice());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
								break;
							case L2PcInstance.STORE_PRIVATE_SELL:
							case L2PcInstance.STORE_PRIVATE_PACKAGE_SELL:
								if (!Config.OFFLINE_TRADE_ENABLE)
									continue;
								title = pc.getSellList().getTitle();
								for (TradeItem i : pc.getSellList().getItems())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getObjectId());
									stm_items.setLong(3, i.getCount());
									stm_items.setLong(4, i.getPrice());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
								break;
							case L2PcInstance.STORE_PRIVATE_MANUFACTURE:
								if (!Config.OFFLINE_CRAFT_ENABLE)
									continue;
								title = pc.getCreateList().getStoreName();
								for (L2ManufactureItem i : pc.getCreateList().getList())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getRecipeId());
									stm_items.setLong(3, 0);
									stm_items.setLong(4, i.getCost());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
						}
						stm3.setString(4, title);
						stm3.executeUpdate();
						stm3.clearParameters();
						con.commit(); // flush
					}
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
				}
			}
			_log.info("Offline traders stored.");
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING,"OfflineTradersTable[storeTradeItems()]: Error while saving offline traders: " + e,e);
		}
	}

	public static void storeOffliners()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement stm = con.prepareStatement(CLEAR_OFFLINE_TABLE);
			stm.execute();
			stm.close();
			stm = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS);
			stm.execute();
			stm.close();

			con.setAutoCommit(false); // avoid halfway done
			stm = con.prepareStatement(SAVE_OFFLINE_STATUS);
			PreparedStatement stm_items = con.prepareStatement(SAVE_ITEMS);

			//TextBuilder items = TextBuilder.newInstance();
			for (L2PcInstance pc : L2World.getInstance().getAllPlayersArray())
			{
				try
				{
					if ((pc.getPrivateStoreType() != L2PcInstance.STORE_PRIVATE_NONE) && (pc.getClient() == null || pc.getClient().isDetached()))
					{
						stm.setInt(1, pc.getObjectId()); //Char Id
						stm.setLong(2, pc.getOfflineStartTime());
						stm.setInt(3, pc.getPrivateStoreType()); //store type
						String title = null;

						switch (pc.getPrivateStoreType())
						{
							case L2PcInstance.STORE_PRIVATE_BUY:
								if (!Config.OFFLINE_TRADE_ENABLE)
									continue;
								title = pc.getBuyList().getTitle();
								for (TradeItem i : pc.getBuyList().getItems())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getItem().getItemId());
									stm_items.setLong(3, i.getCount());
									stm_items.setLong(4, i.getPrice());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
								break;
							case L2PcInstance.STORE_PRIVATE_SELL:
							case L2PcInstance.STORE_PRIVATE_PACKAGE_SELL:
								if (!Config.OFFLINE_TRADE_ENABLE)
									continue;
								title = pc.getSellList().getTitle();
								for (TradeItem i : pc.getSellList().getItems())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getObjectId());
									stm_items.setLong(3, i.getCount());
									stm_items.setLong(4, i.getPrice());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
								break;
							case L2PcInstance.STORE_PRIVATE_MANUFACTURE:
								if (!Config.OFFLINE_CRAFT_ENABLE)
									continue;
								title = pc.getCreateList().getStoreName();
								for (L2ManufactureItem i : pc.getCreateList().getList())
								{
									stm_items.setInt(1, pc.getObjectId());
									stm_items.setInt(2, i.getRecipeId());
									stm_items.setLong(3, 0);
									stm_items.setLong(4, i.getCost());
									stm_items.executeUpdate();
									stm_items.clearParameters();
								}
						}
						stm.setString(4, title);
						stm.executeUpdate();
						stm.clearParameters();
						con.commit(); // flush
					}
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "OfflineTradersTable[storeTradeItems()]: Error while saving offline trader: " + pc.getObjectId() + " " + e, e);
				}
			}
			stm.close();
			stm_items.close();
			_log.info("Offline traders stored.");
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING,"OfflineTradersTable[storeTradeItems()]: Error while saving offline traders: " + e,e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement stm1=con.prepareStatement(CLEAR_OFFLINE_TABLE); PreparedStatement stm2=con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS); PreparedStatement stm3=con.prepareStatement(SAVE_OFFLINE_STATUS); PreparedStatement stm_items=con.prepareStatement(SAVE_ITEMS)) in method public storeOffliners() : void from class com.l2jserver.gameserver.datatables.OfflineTradersTable


	public static void restoreOfflineTraders()
	{
		_log.info("Loading offline traders...");
		int nTraders = 0;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement stm = con.createStatement();
			ResultSet rs = stm.executeQuery(LOAD_OFFLINE_STATUS))
		{
			while (rs.next())
			{
				long time = rs.getLong("time");
				if (Config.OFFLINE_MAX_DAYS > 0)
				{
					Calendar cal = Calendar.getInstance();
					cal.setTimeInMillis(time);
					cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
					if (cal.getTimeInMillis() <= System.currentTimeMillis())
						continue;
				}

				int type = rs.getInt("type");
				if (type == L2PcInstance.STORE_PRIVATE_NONE)
					continue;

				L2PcInstance player = null;

				try
				{
					L2GameClient client = new L2GameClient(null);
					client.setDetached(true);
					player = L2PcInstance.load(rs.getInt("charId"));
					client.setActiveChar(player);
					player.setOnlineStatus(true, false);
					client.setAccountName(player.getAccountNamePlayer());
					client.setState(GameClientState.IN_GAME);
					player.setClient(client);
					player.setOfflineStartTime(time);
					player.spawnMe(player.getX(), player.getY(), player.getZ());
					LoginServerThread.getInstance().addGameServerLogin(player.getAccountName(), client);
					try (PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS))
					{
						stm_items.setInt(1, player.getObjectId());
						try (ResultSet items = stm_items.executeQuery())
						{
							switch (type)
							{
								case L2PcInstance.STORE_PRIVATE_BUY:
									while (items.next())
									{
										if (player.getBuyList().addItemByItemId(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
											throw new NullPointerException();
									}
									player.getBuyList().setTitle(rs.getString("title"));
									break;
								case L2PcInstance.STORE_PRIVATE_SELL:
								case L2PcInstance.STORE_PRIVATE_PACKAGE_SELL:
									while (items.next())
									{
										if (player.getSellList().addItem(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
											throw new NullPointerException();
									}
									player.getSellList().setTitle(rs.getString("title"));
									player.getSellList().setPackaged(type == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL);
									break;
								case L2PcInstance.STORE_PRIVATE_MANUFACTURE:
									L2ManufactureList createList = new L2ManufactureList();
									while (items.next())
									{
										createList.add(new L2ManufactureItem(items.getInt(2), items.getLong(4)));
									}
									player.setCreateList(createList);
									player.getCreateList().setStoreName(rs.getString("title"));
									break;
							}
						}
					}
					player.sitDown();
					if (Config.OFFLINE_SET_NAME_COLOR)
						player.getAppearance().setNameColor(Config.OFFLINE_NAME_COLOR);
					player.setPrivateStoreType(type);
					player.setOnlineStatus(true, true);
					player.restoreEffects();
					player.broadcastUserInfo();
					nTraders++;
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "OfflineTradersTable[loadOffliners()]: Error loading trader: "+player,e);
					if (player != null)
					{
						player.deleteMe();
					}
				}
			}

			_log.info("Loaded: " +nTraders+ " offline trader(s)");

			try (Statement stm1 = con.createStatement())
			{
				stm1.execute(CLEAR_OFFLINE_TABLE);
				stm1.execute(CLEAR_OFFLINE_TABLE_ITEMS);
			}
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "OfflineTradersTable[loadOffliners()]: Error while loading offline traders: ",e);
		}
	}

	public static void restoreOfflineTraders()
	{
		_log.info("Loading offline traders...");
		Connection con = null;
		int nTraders = 0;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement stm = con.prepareStatement(LOAD_OFFLINE_STATUS);
			ResultSet rs = stm.executeQuery();
			while (rs.next())
			{
				long time = rs.getLong("time");
				if (Config.OFFLINE_MAX_DAYS > 0)
				{
					Calendar cal = Calendar.getInstance();
					cal.setTimeInMillis(time);
					cal.add(Calendar.DAY_OF_YEAR, Config.OFFLINE_MAX_DAYS);
					if (cal.getTimeInMillis() <= System.currentTimeMillis())
						continue;
				}

				int type = rs.getInt("type");
				if (type == L2PcInstance.STORE_PRIVATE_NONE)
					continue;

				L2PcInstance player = null;

				try
				{
					L2GameClient client = new L2GameClient(null);
					client.setDetached(true);
					player = L2PcInstance.load(rs.getInt("charId"));
					client.setActiveChar(player);
					player.setOnlineStatus(true, false);
					client.setAccountName(player.getAccountNamePlayer());
					client.setState(GameClientState.IN_GAME);
					player.setClient(client);
					player.setOfflineStartTime(time);
					player.spawnMe(player.getX(), player.getY(), player.getZ());
					LoginServerThread.getInstance().addGameServerLogin(player.getAccountName(), client);
					PreparedStatement stm_items = con.prepareStatement(LOAD_OFFLINE_ITEMS);
					stm_items.setInt(1, player.getObjectId());
					ResultSet items = stm_items.executeQuery();

					switch (type)
					{
						case L2PcInstance.STORE_PRIVATE_BUY:
							while (items.next())
							{
								if (player.getBuyList().addItemByItemId(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
									throw new NullPointerException();
							}
							player.getBuyList().setTitle(rs.getString("title"));
							break;
						case L2PcInstance.STORE_PRIVATE_SELL:
						case L2PcInstance.STORE_PRIVATE_PACKAGE_SELL:
							while (items.next())
							{
								if (player.getSellList().addItem(items.getInt(2), items.getLong(3), items.getLong(4)) == null)
									throw new NullPointerException();
							}
							player.getSellList().setTitle(rs.getString("title"));
							player.getSellList().setPackaged(type == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL);
							break;
						case L2PcInstance.STORE_PRIVATE_MANUFACTURE:
							L2ManufactureList createList = new L2ManufactureList();
							while (items.next())
							{
								createList.add(new L2ManufactureItem(items.getInt(2), items.getLong(4)));
							}
							player.setCreateList(createList);
							player.getCreateList().setStoreName(rs.getString("title"));
							break;
					}
					items.close();
					stm_items.close();

					player.sitDown();
					if (Config.OFFLINE_SET_NAME_COLOR)
						player.getAppearance().setNameColor(Config.OFFLINE_NAME_COLOR);
					player.setPrivateStoreType(type);
					player.setOnlineStatus(true, true);
					player.restoreEffects();
					player.broadcastUserInfo();
					nTraders++;
				}
				catch (Exception e)
				{
					_log.log(Level.WARNING, "OfflineTradersTable[loadOffliners()]: Error loading trader: "+player,e);
					if (player != null)
					{
						player.deleteMe();
					}
				}
			}
			rs.close();
			stm.close();
			_log.info("Loaded: " +nTraders+ " offline trader(s)");
			stm = con.prepareStatement(CLEAR_OFFLINE_TABLE);
			stm.execute();
			stm.close();
			stm = con.prepareStatement(CLEAR_OFFLINE_TABLE_ITEMS);
			stm.execute();
			stm.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "OfflineTradersTable[loadOffliners()]: Error while loading offline traders: ",e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement stm=con.createStatement(); ResultSet rs=stm.executeQuery(LOAD_OFFLINE_STATUS)) in method public restoreOfflineTraders() : void from class com.l2jserver.gameserver.datatables.OfflineTradersTable


	public boolean doesPetNameExist(String name, int petNpcId)
	{
		boolean result = true;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id IN (?)"))
		{
			ps.setString(1, name);
			StringBuilder cond = new StringBuilder();
			for (int it : PetDataTable.getPetItemsByNpc(petNpcId))
			{
				if (!cond.toString().isEmpty())
					cond.append(", ");
				cond.append(it);
			}
			ps.setString(2, cond.toString());
			try (ResultSet rs = ps.executeQuery())
			{
				result = rs.next();
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing petname:" + e.getMessage(), e);
		}
		return result;
	}

	public boolean doesPetNameExist(String name, int petNpcId)
	{
		boolean result = true;
		Connection con = null;

		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id IN (?)");
			statement.setString(1, name);

			StringBuilder cond = new StringBuilder();
			for (int it : PetDataTable.getPetItemsByNpc(petNpcId))
			{
				if (!cond.toString().isEmpty())
					cond.append(", ");
				cond.append(it);
			}
			statement.setString(2, cond.toString());
			ResultSet rset = statement.executeQuery();
			result = rset.next();
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing petname:" + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		return result;
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT name FROM pets p, items i WHERE p.item_obj_id = i.object_id AND name=? AND i.item_id IN (?)")) in method public doesPetNameExist(name String, petNpcId int) : boolean from class com.l2jserver.gameserver.datatables.PetNameTable