	private void updateItemAttributes(Connection con)
	{
		try (PreparedStatement ps = con.prepareStatement("REPLACE INTO item_attributes VALUES(?,?,?,?)"))
		{
			ps.setInt(1, getObjectId());
			if (_augmentation == null)
			{
				ps.setInt(2, -1);
				ps.setInt(3, -1);
				ps.setInt(4, -1);
			}
			else
			{
				ps.setInt(2, _augmentation.getAttributes());
				if (_augmentation.getSkill() == null)
				{
					ps.setInt(3, 0);
					ps.setInt(4, 0);
				}
				else
				{
					ps.setInt(3, _augmentation.getSkill().getId());
					ps.setInt(4, _augmentation.getSkill().getLevel());
				}
			}
			ps.executeUpdate();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "Could not update atributes for item: " + this + " from DB:", e);
		}
	}

	private void updateItemAttributes(Connection con)
	{
		try
		{
			PreparedStatement statement = con.prepareStatement("REPLACE INTO item_attributes VALUES(?,?,?,?)");
			statement.setInt(1, getObjectId());
			if (_augmentation == null)
			{
				statement.setInt(2, -1);
				statement.setInt(3, -1);
				statement.setInt(4, -1);
			}
			else
			{
				statement.setInt(2, _augmentation.getAttributes());
				if (_augmentation.getSkill() == null)
				{
					statement.setInt(3, 0);
					statement.setInt(4, 0);
				}
				else
				{
					statement.setInt(3, _augmentation.getSkill().getId());
					statement.setInt(4, _augmentation.getSkill().getLevel());
				}
			}
			statement.executeUpdate();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "Could not update atributes for item: " + this + " from DB:", e);
		}
	}

Try With Resources try(PreparedStatement ps=con.prepareStatement("REPLACE INTO item_attributes VALUES(?,?,?,?)")) in method private updateItemAttributes(con Connection) : void from class com.l2jserver.gameserver.model.items.instance.L2ItemInstance


	protected L2CommunityServer()
	{
		final String LOG_FOLDER = "log";
		final String LOG_NAME = "./log.cfg";

		File logFolder = new File(Config.DATAPACK_ROOT, LOG_FOLDER);
		logFolder.mkdir();

		try (InputStream is = new FileInputStream(new File(LOG_NAME)))
		{
			LogManager.getLogManager().readConfiguration(is);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

		Config.load();

		_shutdownHandler = Shutdown.getInstance();
		Runtime.getRuntime().addShutdownHook(_shutdownHandler);
		ThreadPoolManager.init();

		GameServerRegistrationTable.getInstance();

		try
		{
			L2DatabaseFactory.getInstance();
		}
		catch (Exception e)
		{
			_log.severe("FATAL: Failed initializing database. Reason: " + e.getMessage());
			System.exit(1);
		}

		// load htm cache
		HtmCache.getInstance();
		try
		{
			_listener = new GameServerListener(new NetConnectionConfig(Config.CONFIGURATION_FILE));
			_listener.start();
			_log.info("Listening for GameServers on " + Config.GAME_SERVER_LOGIN_HOST + ":" + Config.GAME_SERVER_LOGIN_PORT);
		}
		catch (Exception e)
		{
			_log.severe("FATAL: Failed to start the Game Server Listener. Reason: " + e.getMessage());
			e.printStackTrace();
			System.exit(1);
		}
	}

	public L2CommunityServer()
	{
		final String LOG_FOLDER = "log";
		final String LOG_NAME = "./log.cfg";

		File logFolder = new File(Config.DATAPACK_ROOT, LOG_FOLDER);
		logFolder.mkdir();

		InputStream is = null;
		try
		{
			is = new FileInputStream(new File(LOG_NAME));
			LogManager.getLogManager().readConfiguration(is);
			is.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (is != null)
				{
					is.close();
				}
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}

		Config.load();

		_shutdownHandler = Shutdown.getInstance();
		Runtime.getRuntime().addShutdownHook(_shutdownHandler);
		ThreadPoolManager.init();

		GameServerRegistrationTable.getInstance();

		try
		{
			L2DatabaseFactory.getInstance();
		}
		catch (SQLException e)
		{
			_log.severe("FATAL: Failed initializing database. Reason: " + e.getMessage());
			System.exit(1);
		}

		// load htm cache
		HtmCache.getInstance();
		try
		{
			_listener = new GameServerListener(new NetConnectionConfig(Config.CONFIGURATION_FILE));
			_listener.start();
			_log.info("Listening for GameServers on " + Config.GAME_SERVER_LOGIN_HOST + ":" + Config.GAME_SERVER_LOGIN_PORT);
		}
		catch (Exception e)
		{
			_log.severe("FATAL: Failed to start the Game Server Listener. Reason: " + e.getMessage());
			e.printStackTrace();
			System.exit(1);
		}
	}

Try With Resources try(InputStream is=new FileInputStream(new File(LOG_NAME))) in method protected L2CommunityServer() from class com.l2jserver.communityserver.L2CommunityServer


	public void insertindb()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_POST))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postId);
			statement.setInt(3, _postOwnerId);
			statement.setString(4, _postRecipientList);
			statement.setLong(5, _postDate);
			statement.setInt(6, _postTopicId);
			statement.setInt(7, _postForumId);
			statement.setString(8, _postTxt);
			statement.setString(9, _postTitle);
			statement.setInt(10, _postType);
			statement.setInt(11, _postParentId);
			statement.setInt(12, _readCount);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
	}

	public void insertindb()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_POST);
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postId);
			statement.setInt(3, _postOwnerId);
			statement.setString(4, _postRecipientList);
			statement.setLong(5, _postDate);
			statement.setInt(6, _postTopicId);
			statement.setInt(7, _postForumId);
			statement.setString(8, _postTxt);
			statement.setString(9, _postTitle);
			statement.setInt(10, _postType);
			statement.setInt(11, _postParentId);
			statement.setInt(12, _readCount);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}

	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(INSERT_POST)) in method public insertindb() : void from class com.l2jserver.communityserver.model.Post


	@Override
	public String format(LogRecord record)
	{
		TextBuilder output = new TextBuilder();
		output.append('[');
		output.append(dateFmt.format(new Date(record.getMillis())));
		output.append(']');
		output.append(' ');
		output.append(record.getMessage());
		output.append(CRLF);
		if (record.getThrown() != null)
		{
			try (StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw))
			{
				record.getThrown().printStackTrace(pw);
				output.append(sw.toString());
				output.append(CRLF);
			}
			catch (Exception ex)
			{
				//
			}
		}
		return output.toString();
	}

	@Override
	public String format(LogRecord record)
	{
		TextBuilder output = new TextBuilder();
		output.append('[');
		output.append(dateFmt.format(new Date(record.getMillis())));
		output.append(']');
		output.append(' ');
		output.append(record.getMessage());
		output.append(CRLF);
		if (record.getThrown() != null)
		{
			try
			{
				StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw);
				record.getThrown().printStackTrace(pw);
				pw.close();
				output.append(sw.toString());
				output.append(CRLF);
			}
			catch (Exception ex)
			{
			}
		}
		return output.toString();
	}

Try With Resources try(StringWriter sw=new StringWriter(); PrintWriter pw=new PrintWriter(sw)) in method public format(record LogRecord) : String from class com.l2jserver.log.ConsoleLogFormatter


	private final Map<byte[], Boolean> loadRegisteredGameServers()
	{
		final Map<byte[], Boolean> registeredGameServers = new FastMap<>();

		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement statement = con.createStatement();
			ResultSet rset = statement.executeQuery(GET_GAMESERVERS))
		{
			while (rset.next())
			{
				// for (byte b : stringToHex(rset.getString("hex_id")))
				registeredGameServers.put(stringToHex(rset.getString("hex_id")), false);
			}
		}
		catch (SQLException e)
		{
			_log.info(getClass().getName()+": Failed getting gameservers from database");
		}
		return registeredGameServers;
	}

	private final Map<byte[], Boolean> loadRegisteredGameServers()
	{
		final Map<byte[], Boolean> registeredGameServers = new FastMap<>();

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT hex_id FROM registered_gameservers");
			ResultSet rset = statement.executeQuery();

			while (rset.next())
			{
				// for (byte b : stringToHex(rset.getString("hex_id")))
				registeredGameServers.put(stringToHex(rset.getString("hex_id")), false);
			}
			statement.close();
			rset.close();
		}
		catch (SQLException e)
		{

		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		return registeredGameServers;
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement statement=con.createStatement(); ResultSet rset=statement.executeQuery(GET_GAMESERVERS)) in method private loadRegisteredGameServers() : Map<byte[],Boolean> from class com.l2jserver.communityserver.GameServerRegistrationTable


	private void loadDataBase()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(GET_FORUMS))
		{
			statement.setInt(1, _sqlDPId);
			try (ResultSet result = statement.executeQuery())
			{
				while (result.next())
				{
					Forum f = new Forum(_sqlDPId, Integer.parseInt(result.getString("forum_id")));
					int type = result.getInt("forum_type");
					if (type == Forum.CLAN)
					{
						if (getClan(result.getInt("forum_owner_id")) == null)
						{
							// delete this forum
						}
						else
						{
							getClan(result.getInt("forum_owner_id")).setForum(f);
							_forumRoot.put(Integer.parseInt(result.getString("forum_id")), f);
						}
					}
					else if (type == Forum.PLAYER)
					{
						if (getPlayer(result.getInt("forum_owner_id")) == null)
						{
							// delete this forum
						}
						else
						{
							getPlayer(result.getInt("forum_owner_id")).setForum(f);
							_forumRoot.put(Integer.parseInt(result.getString("forum_id")), f);
						}
					}
					if (f.getID() > _lastForumId)
					{
						_lastForumId = f.getID();
					}
				}
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
		catch (SQLException e)
		{
			// _log.warning("data error on Forum (root): " + e);
			e.printStackTrace();
		}
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(GET_CLAN_INTROS))
		{
			statement.setInt(1, _sqlDPId);
			try (ResultSet result = statement.executeQuery())
			{
				while (result.next())
				{
					getClan(result.getInt("clanId")).setIntroduction(result.getString("introduction"));
				}
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
		catch (SQLException e)
		{
			// _log.warning("data error on Forum (root): " + e);
			e.printStackTrace();
		}
		int requestedClanNotices = 0;
		try
		{
			for (L2Clan c : _clans.values())
			{
				if (c == null)
				{
					continue;
				}
				if (_players.containsKey(c.getLordObjId()) && _players.get(c.getLordObjId()).isOnline())
				{
					getGST().sendPacket(new RequestWorldInfo(RequestWorldInfo.CLAN_NOTICE_DATA, c.getClanId(), "", false));
					requestedClanNotices++;
				}
			}
			_log.info("Requesting " + requestedClanNotices + " clan notices from GS.");
		}
		catch (Exception e)
		{
			_log.warning("Data error on Notice Load: " + e);
		}
	}

	private void loadDataBase()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT forum_id, forum_type, forum_owner_id FROM forums WHERE serverId=?");
			statement.setInt(1, _sqlDPId);
			ResultSet result = statement.executeQuery();
			while (result.next())
			{
				Forum f = new Forum(_sqlDPId, Integer.parseInt(result.getString("forum_id")));
				int type = result.getInt("forum_type");
				if (type == Forum.CLAN)
				{
					if (getClan(result.getInt("forum_owner_id")) == null)
					{
						// delete this forum
					}
					else
					{
						getClan(result.getInt("forum_owner_id")).setForum(f);
						_forumRoot.put(Integer.parseInt(result.getString("forum_id")), f);
					}
				}
				else if (type == Forum.PLAYER)
				{
					if (getPlayer(result.getInt("forum_owner_id")) == null)
					{
						// delete this forum
					}
					else
					{
						getPlayer(result.getInt("forum_owner_id")).setForum(f);
						_forumRoot.put(Integer.parseInt(result.getString("forum_id")), f);
					}
				}
				if (f.getID() > _lastForumId)
				{
					_lastForumId = f.getID();
				}
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			// _log.warning("data error on Forum (root): " + e);
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT introduction,clanId FROM clan_introductions WHERE serverId=?");
			statement.setInt(1, _sqlDPId);
			ResultSet result = statement.executeQuery();
			while (result.next())
			{
				getClan(result.getInt("clanId")).setIntroduction(result.getString("introduction"));
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			// _log.warning("data error on Forum (root): " + e);
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		int requestedClanNotices = 0;
		try
		{
			for (L2Clan c : _clans.values())
			{
				if (c == null)
				{
					continue;
				}
				if (_players.containsKey(c.getLordObjId()) && _players.get(c.getLordObjId()).isOnline())
				{
					getGST().sendPacket(new RequestWorldInfo(RequestWorldInfo.CLAN_NOTICE_DATA, c.getClanId(), "", false));
					requestedClanNotices++;
				}
			}
			_log.info("Requesting " + requestedClanNotices + " clan notices from GS.");
		}
		catch (Exception e)
		{
			_log.warning("Data error on Notice Load: " + e);
		}
	}

Try With Resources try(ResultSet result=statement.executeQuery()) in method private loadDataBase() : void from class com.l2jserver.communityserver.communityboard.CommunityBoardManager


	public void storeClanIntro(int clanId, String intro)
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_CLAN_INTRO))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, clanId);
			statement.setString(3, intro);
			statement.setString(4, intro);
			statement.execute();
		}
		catch (SQLException e)
		{
			_log.warning("error while saving new Topic to db " + e);
		}
	}

	public void storeClanIntro(int clanId, String intro)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO clan_introductions (serverId,clanId,introduction) values (?,?,?) ON DUPLICATE KEY UPDATE introduction = ?");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, clanId);
			statement.setString(3, intro);
			statement.setString(4, intro);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Topic to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(INSERT_CLAN_INTRO)) in method public storeClanIntro(clanId int, intro String) : void from class com.l2jserver.communityserver.communityboard.CommunityBoardManager


	public void insertindb()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_COMMENT))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _commentId);
			statement.setInt(3, _commentOwnerId);
			statement.setLong(4, _commentDate);
			statement.setInt(5, _commentPostId);
			statement.setInt(6, _commentTopicId);
			statement.setInt(7, _commentForumId);
			statement.setString(8, _commentTxt);
			statement.execute();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
	}

	public void insertindb()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO comments (serverId, comment_id,comment_ownerid,comment_date,comment_post_id,comment_topic_id,comment_forum_id,comment_txt) values (?,?,?,?,?,?,?,?)");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _commentId);
			statement.setInt(3, _commentOwnerId);
			statement.setLong(4, _commentDate);
			statement.setInt(5, _commentPostId);
			statement.setInt(6, _commentTopicId);
			statement.setInt(7, _commentForumId);
			statement.setString(8, _commentTxt);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(INSERT_COMMENT)) in method public insertindb() : void from class com.l2jserver.communityserver.model.Comment


	public void deleteme()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(DELETE_COMMENT))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _commentForumId);
			statement.setInt(3, _commentTopicId);
			statement.setInt(4, _commentPostId);
			statement.setInt(5, _commentId);
			statement.execute();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	public void deleteme()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM comments WHERE serverId=? AND comment_forum_id=? AND comment_topic_id=? AND comment_Post_id=? AND comment_id=?");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _commentForumId);
			statement.setInt(3, _commentTopicId);
			statement.setInt(4, _commentPostId);
			statement.setInt(5, _commentId);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(DELETE_COMMENT)) in method public deleteme() : void from class com.l2jserver.communityserver.model.Comment


	public void insertindb()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_FORUM))
		{
			// TODO: needs to be changed
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _forumId);
			statement.setString(3, _forumName);
			statement.setInt(4, _forumType);
			statement.setInt(5, _ownerID);
			statement.execute();
		}
		catch (SQLException e)
		{
			_log.warning("error while saving new Forum to db " + e);
		}
	}

	public void insertindb()
	{
		Connection con = null;
		try
		{
			// TODO: needs to be changed
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO forums (serverId,forum_id,forum_name,forum_type,forum_owner_id) values (?,?,?,?,?)");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _forumId);
			statement.setString(3, _forumName);
			statement.setInt(4, _forumType);
			statement.setInt(5, _ownerID);
			statement.execute();
			statement.close();

		}
		catch (Exception e)
		{
			_log.warning("error while saving new Forum to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(INSERT_FORUM)) in method public insertindb() : void from class com.l2jserver.communityserver.model.Forum


	private void loadComments()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(GET_COMMENTS))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postForumId);
			statement.setInt(3, _postTopicId);
			statement.setInt(4, _postId);
			try(ResultSet result = statement.executeQuery())
			{
			while (result.next())
			{
				int commentId = Integer.parseInt(result.getString("comment_id"));
				int commentOwner = Integer.parseInt(result.getString("comment_ownerid"));
				long date = Long.parseLong(result.getString("comment_date"));
				String text = result.getString("comment_txt");
				Comment c = new Comment(ConstructorType.RESTORE, _sqlDPId, commentId, commentOwner, date, _postId, _postTopicId, _postForumId, text);
				_comments.put(commentId, c);
				if (commentId > _lastCommentId)
				{
					_lastCommentId = commentId;
				}
			}
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		catch (Exception e)
		{
			_log.warning("data error on Forum " + _postForumId + " : " + e);
			e.printStackTrace();
		}
	}

	private void loadComments()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT * FROM comments WHERE serverId=? AND comment_forum_id=? AND comment_topic_id=? AND comment_post_id=?");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postForumId);
			statement.setInt(3, _postTopicId);
			statement.setInt(4, _postId);
			ResultSet result = statement.executeQuery();

			while (result.next())
			{
				int commentId = Integer.parseInt(result.getString("comment_id"));
				int commentOwner = Integer.parseInt(result.getString("comment_ownerid"));
				long date = Long.parseLong(result.getString("comment_date"));
				String text = result.getString("comment_txt");
				Comment c = new Comment(ConstructorType.RESTORE, _sqlDPId, commentId, commentOwner, date, _postId, _postTopicId, _postForumId, text);
				_comments.put(commentId, c);
				if (commentId > _lastCommentId)
				{
					_lastCommentId = commentId;
				}
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("data error on Forum " + _postForumId + " : " + e);
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(ResultSet result=statement.executeQuery()) in method private loadComments() : void from class com.l2jserver.communityserver.model.Post


	public void deleteme()
	{
		for (Comment c : _comments.values())
		{
			c.deleteme();
		}
		_comments.clear();
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(DELETE_COMMENT))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postForumId);
			statement.setInt(3, _postTopicId);
			statement.setInt(4, _postId);
			statement.execute();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	public void deleteme()
	{
		for (Comment c : _comments.values())
		{
			c.deleteme();
		}
		_comments.clear();
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM posts WHERE serverId=? AND post_forum_id=? AND post_topic_id=? AND post_id=?");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _postForumId);
			statement.setInt(3, _postTopicId);
			statement.setInt(4, _postId);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(DELETE_COMMENT)) in method public deleteme() : void from class com.l2jserver.communityserver.model.Post


	private void updatePost()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(GET_POSTS))
		{
			statement.setString(1, _postTxt);
			statement.setString(2, _postTitle);
			statement.setString(3, _postRecipientList);
			statement.setInt(4, _readCount);
			statement.setInt(5, _sqlDPId);
			statement.setInt(6, _postId);
			statement.setInt(7, _postTopicId);
			statement.setInt(8, _postForumId);
			statement.execute();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
	}

	private void updatePost()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("UPDATE posts SET post_txt=?,post_title=?,post_recipient_list=?,post_read_count=? WHERE serverId=? AND post_id=? AND post_topic_id=? AND post_forum_id=?");
			statement.setString(1, _postTxt);
			statement.setString(2, _postTitle);
			statement.setString(3, _postRecipientList);
			statement.setInt(4, _readCount);
			statement.setInt(5, _sqlDPId);
			statement.setInt(6, _postId);
			statement.setInt(7, _postTopicId);
			statement.setInt(8, _postForumId);

			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new Post to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(GET_POSTS)) in method private updatePost() : void from class com.l2jserver.communityserver.model.Post


	private void loadPosts()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(GET_POSTS))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _forumId);
			statement.setInt(3, _id);
			try(ResultSet result = statement.executeQuery())
			{
			while (result.next())
			{
				int postId = Integer.parseInt(result.getString("post_id"));
				int postOwner = Integer.parseInt(result.getString("post_ownerid"));
				String recipientList = result.getString("post_recipient_list");
				long date = Long.parseLong(result.getString("post_date"));
				String title = result.getString("post_title");
				String text = result.getString("post_txt");
				int type = Integer.parseInt(result.getString("post_type"));
				int parentId = Integer.parseInt(result.getString("post_parent_id"));
				int readCount = Integer.parseInt(result.getString("post_read_count"));
				Post p = new Post(ConstructorType.RESTORE, _sqlDPId, postId, postOwner, recipientList, parentId, date, _id, _forumId, title, text, type, readCount);
				_posts.put(postId, p);
				if (postId > _lastPostId)
				{
					_lastPostId = postId;
				}
			}
			}
			catch(SQLException e)
			{
				e.printStackTrace();
			}
		}
		catch (SQLException e)
		{
			_log.warning("data error on Forum " + _forumId + " : " + e);
			e.printStackTrace();
		}
	}

	private void loadPosts()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT * FROM posts WHERE serverId=? AND post_forum_id=? AND post_topic_id=?");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _forumId);
			statement.setInt(3, _id);
			ResultSet result = statement.executeQuery();

			while (result.next())
			{
				int postId = Integer.parseInt(result.getString("post_id"));
				int postOwner = Integer.parseInt(result.getString("post_ownerid"));
				String recipientList = result.getString("post_recipient_list");
				long date = Long.parseLong(result.getString("post_date"));
				String title = result.getString("post_title");
				String text = result.getString("post_txt");
				int type = Integer.parseInt(result.getString("post_type"));
				int parentId = Integer.parseInt(result.getString("post_parent_id"));
				int readCount = Integer.parseInt(result.getString("post_read_count"));
				Post p = new Post(ConstructorType.RESTORE, _sqlDPId, postId, postOwner, recipientList, parentId, date, _id, _forumId, title, text, type, readCount);
				_posts.put(postId, p);
				if (postId > _lastPostId)
				{
					_lastPostId = postId;
				}
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("data error on Forum " + _forumId + " : " + e);
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(ResultSet result=statement.executeQuery()) in method private loadPosts() : void from class com.l2jserver.communityserver.model.Topic


	public void insertindb()
	{
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(INSERT_TOPIC))
		{
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _id);
			statement.setInt(3, _forumId);
			statement.setString(4, _topicName);
			statement.setInt(5, _ownerId);
			statement.setInt(6, _permissions);
			statement.execute();
		}
		catch (SQLException e)
		{
			_log.warning("error while saving new Topic to db " + e);
		}
	}

	public void insertindb()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO topics (serverId,topic_id,topic_forum_id,topic_name,topic_ownerid,topic_permissions) values (?,?,?,?,?,?)");
			statement.setInt(1, _sqlDPId);
			statement.setInt(2, _id);
			statement.setInt(3, _forumId);
			statement.setString(4, _topicName);
			statement.setInt(5, _ownerId);
			statement.setInt(6, _permissions);
			statement.execute();
			statement.close();

		}
		catch (Exception e)
		{
			_log.warning("error while saving new Topic to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(INSERT_TOPIC)) in method public insertindb() : void from class com.l2jserver.communityserver.model.Topic


	/**
	 * @param f
	 */
	public void deleteme(Forum f)
	{
		f.rmTopicByID(getID());
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(DELETE_TOPIC))
		{
			statement.setInt(1, getID());
			statement.setInt(2, f.getID());
			statement.execute();
			statement.close();
		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * @param f
	 */
	public void deleteme(Forum f)
	{
		f.rmTopicByID(getID());
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM topics WHERE topic_id=? AND topic_forum_id=?");
			statement.setInt(1, getID());
			statement.setInt(2, f.getID());
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(DELETE_TOPIC)) in method public deleteme(f Forum) : void from class com.l2jserver.communityserver.model.Topic


	public void setPermissions(int val)
	{
		_permissions = val;
		try(Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement(UPDATE_TOPIC))
		{
			statement.setInt(1, _permissions);
			statement.setInt(2, _sqlDPId);
			statement.setInt(3, _id);
			statement.setInt(4, _forumId);
			statement.execute();
		}
		catch (SQLException e)
		{
			_log.warning("error while saving new permissions to db " + e);
		}
	}

	public void setPermissions(int val)
	{
		_permissions = val;
		java.sql.Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("UPDATE topics SET topic_permissions=? WHERE serverId=? AND topic_id=? AND topic_forum_id=?");
			statement.setInt(1, _permissions);
			statement.setInt(2, _sqlDPId);
			statement.setInt(3, _id);
			statement.setInt(4, _forumId);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.warning("error while saving new permissions to db " + e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement(UPDATE_TOPIC)) in method public setPermissions(val int) : void from class com.l2jserver.communityserver.model.Topic


	/**
	 * Save hexadecimal ID of the server in the L2Properties file.
	 * @param serverId the ID of the server whose hexId to save
	 * @param hexId the hexadecimal ID to store
	 * @param fileName name of the L2Properties file
	 */
	public static void saveHexid(int serverId, String hexId, String fileName)
	{
		try
		{
			L2Properties hexSetting = new L2Properties();
			File file = new File(fileName);
			// Create a new empty file only if it doesn't exist
			file.createNewFile();
			try (OutputStream out = new FileOutputStream(file))
			{
				hexSetting.setProperty("ServerID", String.valueOf(serverId));
				hexSetting.setProperty("HexID", hexId);
				hexSetting.store(out, "the hexID to auth into login");
			}
		}
		catch (Exception e)
		{
			_log.warning(StringUtil.concat("Failed to save hex id to ", fileName, " File."));
			_log.warning("Config: " + e.getMessage());
		}
	}

	/**
	 * Save hexadecimal ID of the server in the L2Properties file.
	 * @param serverId the ID of the server whose hexId to save
	 * @param hexId the hexadecimal ID to store
	 * @param fileName name of the L2Properties file
	 */
	public static void saveHexid(int serverId, String hexId, String fileName)
	{
		try
		{
			L2Properties hexSetting = new L2Properties();
			File file = new File(fileName);
			// Create a new empty file only if it doesn't exist
			file.createNewFile();
			OutputStream out = new FileOutputStream(file);
			hexSetting.setProperty("ServerID", String.valueOf(serverId));
			hexSetting.setProperty("HexID", hexId);
			hexSetting.store(out, "the hexID to auth into login");
			out.close();
		}
		catch (Exception e)
		{
			_log.warning(StringUtil.concat("Failed to save hex id to ", fileName, " File."));
			_log.warning("Config: " + e.getMessage());
		}
	}

Try With Resources try(OutputStream out=new FileOutputStream(file)) in method public saveHexid(serverId int, hexId String, fileName String) : void from class com.l2jserver.Config


	/**
	 * Gets the chars on server.
	 * @param account the account
	 */
	private void getCharsOnServer(String account)
	{

		int chars = 0;
		List<Long> charToDel = new ArrayList<>();
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?"))
		{
			ps.setString(1, account);
			try (ResultSet rs = ps.executeQuery())
			{
				while (rs.next())
				{
					chars++;
					long delTime = rs.getLong("deletetime");
					if (delTime != 0)
						charToDel.add(delTime);
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
		}

		ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
		try
		{
			sendPacket(rec);
		}
		catch (IOException e)
		{
			if (Config.DEBUG)
			{
				_log.log(Level.WARNING, "", e);
			}
		}
	}

	private void getCharsOnServer(String account)
	{
		Connection con = null;
		int chars = 0;
		List<Long> charToDel = new ArrayList<>();
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?");
			statement.setString(1, account);
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{
				chars++;
				long delTime = rset.getLong("deletetime");
				if (delTime != 0)
					charToDel.add(delTime);
			}
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Exception: getCharsOnServer: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}

		ReplyCharacters rec = new ReplyCharacters(account, chars, charToDel);
		try
		{
			sendPacket(rec);
		}
		catch (IOException e)
		{
			if (Config.DEBUG)
				_log.log(Level.WARNING, "", e);
		}

	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT deletetime FROM characters WHERE account_name=?")) in method private getCharsOnServer(account String) : void from class com.l2jserver.gameserver.LoginServerThread


	/**
	 * Saves all Seven Signs player data.<br>
	 * Should be called on period change and shutdown only.
	 */
	public void saveSevenSignsData()
	{
		if (Config.DEBUG)
			_log.info("SevenSigns: Saving data to disk.");

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(UPDATE_PLAYER))
		{
			for (StatsSet sevenDat : _signsPlayerData.values())
			{
				ps.setString(1, sevenDat.getString("cabal"));
				ps.setInt(2, sevenDat.getInteger("seal"));
				ps.setInt(3, sevenDat.getInteger("red_stones"));
				ps.setInt(4, sevenDat.getInteger("green_stones"));
				ps.setInt(5, sevenDat.getInteger("blue_stones"));
				ps.setDouble(6, sevenDat.getDouble("ancient_adena_amount"));
				ps.setDouble(7, sevenDat.getDouble("contribution_score"));
				ps.setInt(8, sevenDat.getInteger("charId"));
				ps.execute();
				ps.clearParameters();
				if (Config.DEBUG)
				{
					_log.info("SevenSigns: Updated data in database for char ID " + sevenDat.getInteger("charId") + " (" + sevenDat.getString("cabal") + ")");
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
	}

	/**
	 * Saves all Seven Signs player data.<br>
	 * Should be called on period change and shutdown only.
	 */
	public void saveSevenSignsData()
	{
		if (Config.DEBUG)
			_log.info("SevenSigns: Saving data to disk.");

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

			for (StatsSet sevenDat : _signsPlayerData.values())
			{
				statement.setString(1, sevenDat.getString("cabal"));
				statement.setInt(2, sevenDat.getInteger("seal"));
				statement.setInt(3, sevenDat.getInteger("red_stones"));
				statement.setInt(4, sevenDat.getInteger("green_stones"));
				statement.setInt(5, sevenDat.getInteger("blue_stones"));
				statement.setDouble(6, sevenDat.getDouble("ancient_adena_amount"));
				statement.setDouble(7, sevenDat.getDouble("contribution_score"));
				statement.setInt(8, sevenDat.getInteger("charId"));
				statement.execute();
				statement.clearParameters();
				if (Config.DEBUG)
					_log.info("SevenSigns: Updated data in database for char ID " + sevenDat.getInteger("charId") + " (" + sevenDat.getString("cabal") + ")");
			}
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(UPDATE_PLAYER)) in method public saveSevenSignsData() : void from class com.l2jserver.gameserver.SevenSigns


	public final void saveSevenSignsData(int objectId)
	{
		StatsSet sevenDat = _signsPlayerData.get(objectId);
		if (sevenDat == null)
			return;

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(UPDATE_PLAYER))
		{
			ps.setString(1, sevenDat.getString("cabal"));
			ps.setInt(2, sevenDat.getInteger("seal"));
			ps.setInt(3, sevenDat.getInteger("red_stones"));
			ps.setInt(4, sevenDat.getInteger("green_stones"));
			ps.setInt(5, sevenDat.getInteger("blue_stones"));
			ps.setDouble(6, sevenDat.getDouble("ancient_adena_amount"));
			ps.setDouble(7, sevenDat.getDouble("contribution_score"));
			ps.setInt(8, sevenDat.getInteger("charId"));
			ps.execute();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
	}

	public final void saveSevenSignsData(int objectId)
	{
		StatsSet sevenDat = _signsPlayerData.get(objectId);
		if (sevenDat == null)
			return;

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();

			PreparedStatement statement = con.prepareStatement(UPDATE_PLAYER);
			statement.setString(1, sevenDat.getString("cabal"));
			statement.setInt(2, sevenDat.getInteger("seal"));
			statement.setInt(3, sevenDat.getInteger("red_stones"));
			statement.setInt(4, sevenDat.getInteger("green_stones"));
			statement.setInt(5, sevenDat.getInteger("blue_stones"));
			statement.setDouble(6, sevenDat.getDouble("ancient_adena_amount"));
			statement.setDouble(7, sevenDat.getDouble("contribution_score"));
			statement.setInt(8, sevenDat.getInteger("charId"));
			statement.execute();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(UPDATE_PLAYER)) in method public saveSevenSignsData(objectId int) : void from class com.l2jserver.gameserver.SevenSigns


	public final void saveSevenSignsStatus()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement(UPDATE_STATUS))
		{
			ps.setInt(1, _currentCycle);
			ps.setInt(2, _activePeriod);
			ps.setInt(3, _previousWinner);
			ps.setDouble(4, _dawnStoneScore);
			ps.setInt(5, _dawnFestivalScore);
			ps.setDouble(6, _duskStoneScore);
			ps.setInt(7, _duskFestivalScore);
			ps.setInt(8, _signsSealOwners.get(SEAL_AVARICE));
			ps.setInt(9, _signsSealOwners.get(SEAL_GNOSIS));
			ps.setInt(10, _signsSealOwners.get(SEAL_STRIFE));
			ps.setInt(11, _signsDawnSealTotals.get(SEAL_AVARICE));
			ps.setInt(12, _signsDawnSealTotals.get(SEAL_GNOSIS));
			ps.setInt(13, _signsDawnSealTotals.get(SEAL_STRIFE));
			ps.setInt(14, _signsDuskSealTotals.get(SEAL_AVARICE));
			ps.setInt(15, _signsDuskSealTotals.get(SEAL_GNOSIS));
			ps.setInt(16, _signsDuskSealTotals.get(SEAL_STRIFE));
			ps.setInt(17, SevenSignsFestival.getInstance().getCurrentFestivalCycle());

			for (int i = 0; i < SevenSignsFestival.FESTIVAL_COUNT; i++)
			{
				ps.setInt(18 + i, SevenSignsFestival.getInstance().getAccumulatedBonus(i));
			}
			_lastSave = Calendar.getInstance();
			ps.setLong(18 + SevenSignsFestival.FESTIVAL_COUNT, _lastSave.getTimeInMillis());
			ps.execute();
			if (Config.DEBUG)
				_log.info("SevenSigns: Updated data in database.");
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
	}

	public final void saveSevenSignsStatus()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();

			PreparedStatement statement = con.prepareStatement(UPDATE_STATUS);
			statement.setInt(1, _currentCycle);
			statement.setInt(2, _activePeriod);
			statement.setInt(3, _previousWinner);
			statement.setDouble(4, _dawnStoneScore);
			statement.setInt(5, _dawnFestivalScore);
			statement.setDouble(6, _duskStoneScore);
			statement.setInt(7, _duskFestivalScore);
			statement.setInt(8, _signsSealOwners.get(SEAL_AVARICE));
			statement.setInt(9, _signsSealOwners.get(SEAL_GNOSIS));
			statement.setInt(10, _signsSealOwners.get(SEAL_STRIFE));
			statement.setInt(11, _signsDawnSealTotals.get(SEAL_AVARICE));
			statement.setInt(12, _signsDawnSealTotals.get(SEAL_GNOSIS));
			statement.setInt(13, _signsDawnSealTotals.get(SEAL_STRIFE));
			statement.setInt(14, _signsDuskSealTotals.get(SEAL_AVARICE));
			statement.setInt(15, _signsDuskSealTotals.get(SEAL_GNOSIS));
			statement.setInt(16, _signsDuskSealTotals.get(SEAL_STRIFE));
			statement.setInt(17, SevenSignsFestival.getInstance().getCurrentFestivalCycle());

			for (int i = 0; i < SevenSignsFestival.FESTIVAL_COUNT; i++)
				statement.setInt(18 + i, SevenSignsFestival.getInstance().getAccumulatedBonus(i));

			_lastSave = Calendar.getInstance();
			statement.setLong(18 + SevenSignsFestival.FESTIVAL_COUNT, _lastSave.getTimeInMillis());
			statement.execute();
			statement.close();
			if (Config.DEBUG)
				_log.info("SevenSigns: Updated data in database.");
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSigns: Unable to save data to database: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(UPDATE_STATUS)) in method public saveSevenSignsStatus() : void from class com.l2jserver.gameserver.SevenSigns


	/**
	 * Used to specify cabal-related details for the specified player.<br>
	 * This method checks to see if the player has registered before and will update the database if necessary.
	 * @param objectId
	 * @param chosenCabal
	 * @param chosenSeal
	 * @return the cabal ID the player has joined.
	 */
	public int setPlayerInfo(int objectId, int chosenCabal, int chosenSeal)
	{
		StatsSet currPlayerData = _signsPlayerData.get(objectId);

		if (currPlayerData != null)
		{
			// If the seal validation period has passed,
			// cabal information was removed and so "re-register" player
			currPlayerData.set("cabal", getCabalShortName(chosenCabal));
			currPlayerData.set("seal", chosenSeal);

			_signsPlayerData.put(objectId, currPlayerData);
		}
		else
		{
			currPlayerData = new StatsSet();
			currPlayerData.set("charId", objectId);
			currPlayerData.set("cabal", getCabalShortName(chosenCabal));
			currPlayerData.set("seal", chosenSeal);
			currPlayerData.set("red_stones", 0);
			currPlayerData.set("green_stones", 0);
			currPlayerData.set("blue_stones", 0);
			currPlayerData.set("ancient_adena_amount", 0);
			currPlayerData.set("contribution_score", 0);

			_signsPlayerData.put(objectId, currPlayerData);

			// Update data in database, as we have a new player signing up.
			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement ps = con.prepareStatement(INSERT_PLAYER))
			{
				ps.setInt(1, objectId);
				ps.setString(2, getCabalShortName(chosenCabal));
				ps.setInt(3, chosenSeal);
				ps.execute();

				if (Config.DEBUG)
					_log.info("SevenSigns: Inserted data in DB for char ID " + currPlayerData.getInteger("charId") + " (" + currPlayerData.getString("cabal") + ")");
			}
			catch (SQLException e)
			{
				_log.log(Level.SEVERE, "SevenSigns: Failed to save data: " + e.getMessage(), e);
			}
		}

		// Increasing Seal total score for the player chosen Seal.
		if ("dawn".equals(currPlayerData.getString("cabal")))
			_signsDawnSealTotals.put(chosenSeal, _signsDawnSealTotals.get(chosenSeal) + 1);
		else
			_signsDuskSealTotals.put(chosenSeal, _signsDuskSealTotals.get(chosenSeal) + 1);

		if (!Config.ALT_SEVENSIGNS_LAZY_UPDATE)
			saveSevenSignsStatus();

		return chosenCabal;
	}

	/**
	 * Used to specify cabal-related details for the specified player.<br>
	 * This method checks to see if the player has registered before and will update the database if necessary.
	 * @param objectId
	 * @param chosenCabal
	 * @param chosenSeal
	 * @return the cabal ID the player has joined.
	 */
	public int setPlayerInfo(int objectId, int chosenCabal, int chosenSeal)
	{
		StatsSet currPlayerData = _signsPlayerData.get(objectId);

		if (currPlayerData != null)
		{
			// If the seal validation period has passed,
			// cabal information was removed and so "re-register" player
			currPlayerData.set("cabal", getCabalShortName(chosenCabal));
			currPlayerData.set("seal", chosenSeal);

			_signsPlayerData.put(objectId, currPlayerData);
		}
		else
		{
			currPlayerData = new StatsSet();
			currPlayerData.set("charId", objectId);
			currPlayerData.set("cabal", getCabalShortName(chosenCabal));
			currPlayerData.set("seal", chosenSeal);
			currPlayerData.set("red_stones", 0);
			currPlayerData.set("green_stones", 0);
			currPlayerData.set("blue_stones", 0);
			currPlayerData.set("ancient_adena_amount", 0);
			currPlayerData.set("contribution_score", 0);

			_signsPlayerData.put(objectId, currPlayerData);

			// Update data in database, as we have a new player signing up.
			Connection con = null;
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement(INSERT_PLAYER);
				statement.setInt(1, objectId);
				statement.setString(2, getCabalShortName(chosenCabal));
				statement.setInt(3, chosenSeal);
				statement.execute();
				statement.close();

				if (Config.DEBUG)
					_log.info("SevenSigns: Inserted data in DB for char ID " + currPlayerData.getInteger("charId") + " ("
							+ currPlayerData.getString("cabal") + ")");
			}
			catch (SQLException e)
			{
				_log.log(Level.SEVERE, "SevenSigns: Failed to save data: " + e.getMessage(), e);
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}
		}

		// Increasing Seal total score for the player chosen Seal.
		if ("dawn".equals(currPlayerData.getString("cabal")))
			_signsDawnSealTotals.put(chosenSeal, _signsDawnSealTotals.get(chosenSeal) + 1);
		else
			_signsDuskSealTotals.put(chosenSeal, _signsDuskSealTotals.get(chosenSeal) + 1);

		if (!Config.ALT_SEVENSIGNS_LAZY_UPDATE)
			saveSevenSignsStatus();

		return chosenCabal;
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(INSERT_PLAYER)) in method public setPlayerInfo(objectId int, chosenCabal int, chosenSeal int) : int from class com.l2jserver.gameserver.SevenSigns


	/**
	 * Stores current festival data, basic settings to the properties file
	 * and past high score data to the database.
	 *
	 * If updateSettings = true, then all Seven Signs data is updated in the database.
	 *
	 * @param updateSettings
	 */
	public void saveFestivalData(boolean updateSettings)
	{
		if (Config.DEBUG)
			_log.info("SevenSignsFestival: Saving festival data to disk.");

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement psUpdate = con.prepareStatement("UPDATE seven_signs_festival SET date=?, score=?, members=? WHERE cycle=? AND cabal=? AND festivalId=?");
			PreparedStatement psInsert = con.prepareStatement("INSERT INTO seven_signs_festival (festivalId, cabal, cycle, date, score, members) VALUES (?,?,?,?,?,?)"))
		{
			for (Map<Integer, StatsSet> currCycleData : _festivalData.values())
			{
				for (StatsSet festivalDat : currCycleData.values())
				{
					int festivalCycle = festivalDat.getInteger("cycle");
					int festivalId = festivalDat.getInteger("festivalId");
					String cabal = festivalDat.getString("cabal");

					// Try to update an existing record.
					psUpdate.setLong(1, Long.valueOf(festivalDat.getString("date")));
					psUpdate.setInt(2, festivalDat.getInteger("score"));
					psUpdate.setString(3, festivalDat.getString("members"));
					psUpdate.setInt(4, festivalCycle);
					psUpdate.setString(5, cabal);
					psUpdate.setInt(6, festivalId);

					// If there was no record to update, assume it doesn't exist and add a new one,
					// otherwise continue with the next record to store.
					if (psUpdate.executeUpdate() > 0)
					{
						if (Config.DEBUG)
							_log.info("SevenSignsFestival: Updated data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal + ", FestID = " + festivalId + ")");
						continue;
					}

					psInsert.setInt(1, festivalId);
					psInsert.setString(2, cabal);
					psInsert.setInt(3, festivalCycle);
					psInsert.setLong(4, Long.valueOf(festivalDat.getString("date")));
					psInsert.setInt(5, festivalDat.getInteger("score"));
					psInsert.setString(6, festivalDat.getString("members"));
					psInsert.execute();
					psInsert.clearParameters();

					if (Config.DEBUG)
						_log.info("SevenSignsFestival: Inserted data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal + ", FestID = " + festivalId + ")");
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSignsFestival: Failed to save configuration: " + e.getMessage(), e);
		}

		// Updates Seven Signs DB data also, so call only if really necessary.
		if (updateSettings)
			SevenSigns.getInstance().saveSevenSignsStatus();
	}

	/**
	 * Stores current festival data, basic settings to the properties file
	 * and past high score data to the database.
	 *
	 * If updateSettings = true, then all Seven Signs data is updated in the database.
	 *
	 * @param updateSettings
	 */
	public void saveFestivalData(boolean updateSettings)
	{
		Connection con = null;

		if (Config.DEBUG)
			_log.info("SevenSignsFestival: Saving festival data to disk.");

		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statementUpdate = con.prepareStatement("UPDATE seven_signs_festival SET date=?, score=?, members=? WHERE cycle=? AND cabal=? AND festivalId=?");
			PreparedStatement statementInsert = con.prepareStatement("INSERT INTO seven_signs_festival (festivalId, cabal, cycle, date, score, members) VALUES (?,?,?,?,?,?)");
			for (Map<Integer, StatsSet> currCycleData : _festivalData.values())
			{
				for (StatsSet festivalDat : currCycleData.values())
				{
					int festivalCycle = festivalDat.getInteger("cycle");
					int festivalId = festivalDat.getInteger("festivalId");
					String cabal = festivalDat.getString("cabal");

					// Try to update an existing record.
					statementUpdate.setLong(1, Long.valueOf(festivalDat.getString("date")));
					statementUpdate.setInt(2, festivalDat.getInteger("score"));
					statementUpdate.setString(3, festivalDat.getString("members"));
					statementUpdate.setInt(4, festivalCycle);
					statementUpdate.setString(5, cabal);
					statementUpdate.setInt(6, festivalId);

					// If there was no record to update, assume it doesn't exist and add a new one,
					// otherwise continue with the next record to store.
					if (statementUpdate.executeUpdate() > 0)
					{
						if (Config.DEBUG)
							_log.info("SevenSignsFestival: Updated data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal + ", FestID = " + festivalId + ")");
						continue;
					}

					statementInsert.setInt(1, festivalId);
					statementInsert.setString(2, cabal);
					statementInsert.setInt(3, festivalCycle);
					statementInsert.setLong(4, Long.valueOf(festivalDat.getString("date")));
					statementInsert.setInt(5, festivalDat.getInteger("score"));
					statementInsert.setString(6, festivalDat.getString("members"));
					statementInsert.execute();
					statementInsert.clearParameters();

					if (Config.DEBUG)
						_log.info("SevenSignsFestival: Inserted data in DB (Cycle = " + festivalCycle + ", Cabal = " + cabal + ", FestID = " + festivalId + ")");
				}
			}
			statementUpdate.close();
			statementInsert.close();

			// Updates Seven Signs DB data also, so call only if really necessary.
			if (updateSettings)
				SevenSigns.getInstance().saveSevenSignsStatus();
		}
		catch (SQLException e)
		{
			_log.log(Level.SEVERE, "SevenSignsFestival: Failed to save configuration: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement psUpdate=con.prepareStatement("UPDATE seven_signs_festival SET date=?, score=?, members=? WHERE cycle=? AND cabal=? AND festivalId=?"); PreparedStatement psInsert=con.prepareStatement("INSERT INTO seven_signs_festival (festivalId, cabal, cycle, date, score, members) VALUES (?,?,?,?,?,?)")) in method public saveFestivalData(updateSettings boolean) : void from class com.l2jserver.gameserver.SevenSignsFestival


	private void addReputationPointsForPartyMemberClan(String partyMemberName)
	{
		L2PcInstance player = L2World.getInstance().getPlayer(partyMemberName);
		if (player != null)
		{
			if (player.getClan() != null)
			{
				player.getClan().addReputationScore(Config.FESTIVAL_WIN_POINTS, true);
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
				sm.addString(partyMemberName);
				sm.addNumber(Config.FESTIVAL_WIN_POINTS);
				player.getClan().broadcastToOnlineMembers(sm);
			}
		}
		else
		{
			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement ps = con.prepareStatement(GET_CLAN_NAME))
			{
				ps.setString(1, partyMemberName);
				try (ResultSet rs = ps.executeQuery())
				{
					if (rs.next())
					{
						String clanName = rs.getString("clan_name");
						if (clanName != null)
						{
							L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
							if (clan != null)
							{
								clan.addReputationScore(Config.FESTIVAL_WIN_POINTS, true);
								SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
								sm.addString(partyMemberName);
								sm.addNumber(Config.FESTIVAL_WIN_POINTS);
								clan.broadcastToOnlineMembers(sm);
							}
						}
					}
				}
			}
			catch (Exception e)
			{
				_log.log(Level.WARNING, "Could not get clan name of " + partyMemberName + ": " + e.getMessage(), e);
			}
		}
	}

	private void addReputationPointsForPartyMemberClan(String partyMemberName)
	{
		L2PcInstance player = L2World.getInstance().getPlayer(partyMemberName);
		if (player != null)
		{
			if (player.getClan() != null)
			{
				player.getClan().addReputationScore(Config.FESTIVAL_WIN_POINTS, true);
				SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
				sm.addString(partyMemberName);
				sm.addNumber(Config.FESTIVAL_WIN_POINTS);
				player.getClan().broadcastToOnlineMembers(sm);
			}
		}
		else
		{
			Connection con = null;

			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement(GET_CLAN_NAME);
				statement.setString(1, partyMemberName);
				ResultSet rset = statement.executeQuery();
				if (rset.next())
				{
					String clanName = rset.getString("clan_name");
					if (clanName != null)
					{
						L2Clan clan = ClanTable.getInstance().getClanByName(clanName);
						if (clan != null)
						{
							clan.addReputationScore(Config.FESTIVAL_WIN_POINTS, true);
							SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_IN_HIGHEST_RANKED_PARTY_IN_FESTIVAL_OF_DARKNESS_AND_GAINED_S2_REPUTATION);
							sm.addString(partyMemberName);
							sm.addNumber(Config.FESTIVAL_WIN_POINTS);
							clan.broadcastToOnlineMembers(sm);
						}
					}
				}

				rset.close();
				statement.close();
			}
			catch (Exception e)
			{
				_log.log(Level.WARNING, "Could not get clan name of " + partyMemberName + ": " + e.getMessage(), e);
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement(GET_CLAN_NAME)) in method private addReputationPointsForPartyMemberClan(partyMemberName String) : void from class com.l2jserver.gameserver.SevenSignsFestival


	protected TradeController()
	{
		_lists.clear();
		// Initialize Shop buy list
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			Statement s = con.createStatement();
			ResultSet rs1 = s.executeQuery("SELECT  shop_id, npc_id FROM merchant_shopids"))
		{
			int itemId, price, maxCount, currentCount, time;
			long saveTimer;
			try (PreparedStatement ps = con.prepareStatement("SELECT item_id, price, shop_id, "
					+ L2DatabaseFactory.getInstance().safetyString("order")
					+ ", count, currentCount, time, savetimer FROM merchant_buylists WHERE shop_id=? ORDER BY "
					+ L2DatabaseFactory.getInstance().safetyString("order") + " ASC"))
			{
				while (rs1.next())
				{
					ps.setString(1, String.valueOf(rs1.getInt("shop_id")));
					try (ResultSet rs2 = ps.executeQuery())
					{
						ps.clearParameters();

						int shopId = rs1.getInt("shop_id");
						L2TradeList buy1 = new L2TradeList(shopId);

						while (rs2.next())
						{
							itemId = rs2.getInt("item_id");
							price = rs2.getInt("price");
							maxCount = rs2.getInt("count");
							currentCount = rs2.getInt("currentCount");
							time = rs2.getInt("time");
							saveTimer = rs2.getLong("saveTimer");

							L2TradeItem item = new L2TradeItem(shopId, itemId);
							if (ItemTable.getInstance().getTemplate(itemId) == null)
							{
								_log.warning("Skipping itemId: " + itemId + " on buylistId: " + buy1.getListId() + ", missing data for that item.");
								continue;
							}

							if (price <= -1)
							{
								price = ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
							}

							if (Config.DEBUG)
							{
								// debug
								double diff = ((double) (price)) / ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
								if (diff < 0.8 || diff > 1.2)
								{
									_log.severe("PRICING DEBUG: TradeListId: " + buy1.getListId() + " -  ItemId: " + itemId + " ("
											+ ItemTable.getInstance().getTemplate(itemId).getName() + ") diff: " + diff + " - Price: " + price
											+ " - Reference: " + ItemTable.getInstance().getTemplate(itemId).getReferencePrice());
								}
							}

							item.setPrice(price);

							item.setRestoreDelay(time);
							item.setNextRestoreTime(saveTimer);
							item.setMaxCount(maxCount);

							if (currentCount > -1)
							{
								item.setCurrentCount(currentCount);
							}
							else
							{
								item.setCurrentCount(maxCount);
							}

							buy1.addItem(item);
						}

						buy1.setNpcId(rs1.getString("npc_id"));
						_lists.put(buy1.getListId(), buy1);
						_nextListId = Math.max(_nextListId, buy1.getListId() + 1);
					}
				}
			}
			_log.info("TradeController: Loaded " + _lists.size() + " Buylists.");
		}
		catch (Exception e)
		{
			// problem with initializing spawn, go to next one
			_log.log(Level.WARNING, "TradeController: Buylists could not be initialized: " + e.getMessage(), e);
		}

		// If enabled, initialize the custom buy list
		if (Config.CUSTOM_MERCHANT_TABLES)
		{
			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
				Statement s = con.createStatement();
				ResultSet rset1 = s.executeQuery("SELECT  shop_id, npc_id FROM custom_merchant_shopids"))
			{
				int initialSize = _lists.size();
				int itemId, price, maxCount, currentCount, time;
				long saveTimer;
				PreparedStatement statement = con.prepareStatement("SELECT item_id, price, shop_id, "
						+ L2DatabaseFactory.getInstance().safetyString("order")
						+ ", count, currentCount, time, savetimer FROM custom_merchant_buylists WHERE shop_id=? ORDER BY "
						+ L2DatabaseFactory.getInstance().safetyString("order") + " ASC");
				while (rset1.next())
				{
					statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
					ResultSet rset = statement.executeQuery();
					statement.clearParameters();

					int shopId = rset1.getInt("shop_id");
					L2TradeList buy1 = new L2TradeList(shopId);

					while (rset.next())
					{
						itemId = rset.getInt("item_id");
						price = rset.getInt("price");
						maxCount = rset.getInt("count");
						currentCount = rset.getInt("currentCount");
						time = rset.getInt("time");
						saveTimer = rset.getLong("saveTimer");

						L2TradeItem item = new L2TradeItem(shopId, itemId);
						if (ItemTable.getInstance().getTemplate(itemId) == null)
						{
							_log.warning("Skipping itemId: " + itemId + " on buylistId: " + buy1.getListId()
									+ ", missing data for that item.");
							continue;
						}

						if (price <= -1)
						{
							price = ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
						}

						if (Config.DEBUG)
						{
							// debug
							double diff = ((double) (price)) / ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
							if (diff < 0.8 || diff > 1.2)
							{
								_log.severe("PRICING DEBUG: TradeListId: " + buy1.getListId() + " -  ItemId: " + itemId + " ("
										+ ItemTable.getInstance().getTemplate(itemId).getName() + ") diff: " + diff + " - Price: " + price
										+ " - Reference: " + ItemTable.getInstance().getTemplate(itemId).getReferencePrice());
							}
						}

						item.setPrice(price);

						item.setRestoreDelay(time);
						item.setNextRestoreTime(saveTimer);
						item.setMaxCount(maxCount);

						if (currentCount > -1)
						{
							item.setCurrentCount(currentCount);
						}
						else
						{
							item.setCurrentCount(maxCount);
						}

						buy1.addItem(item);
					}

					buy1.setNpcId(rset1.getString("npc_id"));
					_lists.put(buy1.getListId(), buy1);
					_nextListId = Math.max(_nextListId, buy1.getListId() + 1);

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

				_log.info("TradeController: Loaded " + (_lists.size() - initialSize) + " Custom Buylists.");

			}
			catch (Exception e)
			{
				// problem with initializing spawn, go to next one
				_log.log(Level.WARNING, "TradeController: Buylists could not be initialized: " + e.getMessage(), e);
			}
		}
	}

	protected TradeController()
	{
		_lists.clear();
		Connection con = null;

		/*
		 * Initialize Shop buylist
		 */
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement1 = con.prepareStatement("SELECT  shop_id, npc_id FROM merchant_shopids");
			ResultSet rset1 = statement1.executeQuery();

			int itemId, price, maxCount, currentCount, time;
			long saveTimer;
			PreparedStatement statement = con.prepareStatement("SELECT item_id, price, shop_id, "
					+ L2DatabaseFactory.getInstance().safetyString("order")
					+ ", count, currentCount, time, savetimer FROM merchant_buylists WHERE shop_id=? ORDER BY "
					+ L2DatabaseFactory.getInstance().safetyString("order") + " ASC");
			while (rset1.next())
			{
				statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
				ResultSet rset = statement.executeQuery();
				statement.clearParameters();

				int shopId = rset1.getInt("shop_id");
				L2TradeList buy1 = new L2TradeList(shopId);

				while (rset.next())
				{
					itemId = rset.getInt("item_id");
					price = rset.getInt("price");
					maxCount = rset.getInt("count");
					currentCount = rset.getInt("currentCount");
					time = rset.getInt("time");
					saveTimer = rset.getLong("saveTimer");

					L2TradeItem item = new L2TradeItem(shopId, itemId);
					if (ItemTable.getInstance().getTemplate(itemId) == null)
					{
						_log.warning("Skipping itemId: " + itemId + " on buylistId: " + buy1.getListId() + ", missing data for that item.");
						continue;
					}

					if (price <= -1)
					{
						price = ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
					}

					if (Config.DEBUG)
					{
						// debug
						double diff = ((double) (price)) / ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
						if (diff < 0.8 || diff > 1.2)
						{
							_log.severe("PRICING DEBUG: TradeListId: " + buy1.getListId() + " -  ItemId: " + itemId + " ("
									+ ItemTable.getInstance().getTemplate(itemId).getName() + ") diff: " + diff + " - Price: " + price
									+ " - Reference: " + ItemTable.getInstance().getTemplate(itemId).getReferencePrice());
						}
					}

					item.setPrice(price);

					item.setRestoreDelay(time);
					item.setNextRestoreTime(saveTimer);
					item.setMaxCount(maxCount);

					if (currentCount > -1)
					{
						item.setCurrentCount(currentCount);
					}
					else
					{
						item.setCurrentCount(maxCount);
					}

					buy1.addItem(item);
				}

				buy1.setNpcId(rset1.getString("npc_id"));
				_lists.put(buy1.getListId(), buy1);
				_nextListId = Math.max(_nextListId, buy1.getListId() + 1);

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

			_log.info("TradeController: Loaded " + _lists.size() + " Buylists.");
		}
		catch (Exception e)
		{
			// problem with initializing spawn, go to next one
			_log.log(Level.WARNING, "TradeController: Buylists could not be initialized: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}

		/*
		 * If enabled, initialize the custom buylist
		 */
		if (Config.CUSTOM_MERCHANT_TABLES)
		{
			try
			{
				int initialSize = _lists.size();
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement1 = con.prepareStatement("SELECT  shop_id, npc_id FROM custom_merchant_shopids");
				ResultSet rset1 = statement1.executeQuery();

				int itemId, price, maxCount, currentCount, time;
				long saveTimer;
				PreparedStatement statement = con.prepareStatement("SELECT item_id, price, shop_id, "
						+ L2DatabaseFactory.getInstance().safetyString("order")
						+ ", count, currentCount, time, savetimer FROM custom_merchant_buylists WHERE shop_id=? ORDER BY "
						+ L2DatabaseFactory.getInstance().safetyString("order") + " ASC");
				while (rset1.next())
				{
					statement.setString(1, String.valueOf(rset1.getInt("shop_id")));
					ResultSet rset = statement.executeQuery();
					statement.clearParameters();

					int shopId = rset1.getInt("shop_id");
					L2TradeList buy1 = new L2TradeList(shopId);

					while (rset.next())
					{
						itemId = rset.getInt("item_id");
						price = rset.getInt("price");
						maxCount = rset.getInt("count");
						currentCount = rset.getInt("currentCount");
						time = rset.getInt("time");
						saveTimer = rset.getLong("saveTimer");

						L2TradeItem item = new L2TradeItem(shopId, itemId);
						if (ItemTable.getInstance().getTemplate(itemId) == null)
						{
							_log.warning("Skipping itemId: " + itemId + " on buylistId: " + buy1.getListId()
									+ ", missing data for that item.");
							continue;
						}

						if (price <= -1)
						{
							price = ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
						}

						if (Config.DEBUG)
						{
							// debug
							double diff = ((double) (price)) / ItemTable.getInstance().getTemplate(itemId).getReferencePrice();
							if (diff < 0.8 || diff > 1.2)
							{
								_log.severe("PRICING DEBUG: TradeListId: " + buy1.getListId() + " -  ItemId: " + itemId + " ("
										+ ItemTable.getInstance().getTemplate(itemId).getName() + ") diff: " + diff + " - Price: " + price
										+ " - Reference: " + ItemTable.getInstance().getTemplate(itemId).getReferencePrice());
							}
						}

						item.setPrice(price);

						item.setRestoreDelay(time);
						item.setNextRestoreTime(saveTimer);
						item.setMaxCount(maxCount);

						if (currentCount > -1)
						{
							item.setCurrentCount(currentCount);
						}
						else
						{
							item.setCurrentCount(maxCount);
						}

						buy1.addItem(item);
					}

					buy1.setNpcId(rset1.getString("npc_id"));
					_lists.put(buy1.getListId(), buy1);
					_nextListId = Math.max(_nextListId, buy1.getListId() + 1);

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

				_log.info("TradeController: Loaded " + (_lists.size() - initialSize) + " Custom Buylists.");

			}
			catch (Exception e)
			{
				// problem with initializing spawn, go to next one
				_log.log(Level.WARNING, "TradeController: Buylists could not be initialized: " + e.getMessage(), e);
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); Statement s=con.createStatement(); ResultSet rs1=s.executeQuery("SELECT  shop_id, npc_id FROM merchant_shopids")) in method protected TradeController() from class com.l2jserver.gameserver.TradeController


	public void dataCountStore()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("UPDATE merchant_buylists SET currentCount = ? WHERE item_id = ? AND shop_id = ?"))
		{
			for (L2TradeList list : _lists.values())
			{
				if (list.hasLimitedStockItem())
				{
					for (L2TradeItem item : list.getItems())
					{
						long currentCount;
						if (item.hasLimitedStock() && (currentCount = item.getCurrentCount()) < item.getMaxCount())
						{
							statement.setLong(1, currentCount);
							statement.setInt(2, item.getItemId());
							statement.setInt(3, list.getListId());
							statement.executeUpdate();
							statement.clearParameters();
						}
					}
				}
			}
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "TradeController: Could not store Count Item: " + e.getMessage(), e);
		}
	}

	public void dataCountStore()
	{
		Connection con = null;
		int listId;

		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("UPDATE merchant_buylists SET currentCount=? WHERE item_id=? AND shop_id=?");
			for (L2TradeList list : _lists.values())
			{
				if (list.hasLimitedStockItem())
				{
					listId = list.getListId();

					for (L2TradeItem item : list.getItems())
					{
						long currentCount;
						if (item.hasLimitedStock() && (currentCount = item.getCurrentCount()) < item.getMaxCount())
						{
							statement.setLong(1, currentCount);
							statement.setInt(2, item.getItemId());
							statement.setInt(3, listId);
							statement.executeUpdate();
							statement.clearParameters();
						}
					}
				}
			}
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.SEVERE, "TradeController: Could not store Count Item: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement=con.prepareStatement("UPDATE merchant_buylists SET currentCount = ? WHERE item_id = ? AND shop_id = ?")) in method public dataCountStore() : void from class com.l2jserver.gameserver.TradeController


	public void convertOldPedgeFiles()
	{
		final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
		final File[] files = dir.listFiles(new OldPledgeFilter());
		for (File file : files)
		{
			int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));
			_log.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);
			final L2Clan clan = ClanTable.getInstance().getClan(clanId);
			if (clan != null)
			{
				removeOldPledgeCrest(clan.getCrestId());
				int newId = IdFactory.getInstance().getNextId();
				file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
				_log.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");

				try (Connection con = L2DatabaseFactory.getInstance().getConnection();
					PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
				{
					ps.setInt(1, newId);
					ps.setInt(2, clan.getClanId());
					ps.executeUpdate();
				}
				catch (SQLException e)
				{
					_log.log(Level.WARNING, "Could not update the crest id:" + e.getMessage(), e);
				}
				clan.setCrestId(newId);
			}
			else
			{
				_log.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
				file.delete();
			}
		}
	}

	public void convertOldPedgeFiles()
	{
		final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
		final File[] files = dir.listFiles(new OldPledgeFilter());
		for (File file : files)
		{
			int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));
			_log.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);
			final L2Clan clan = ClanTable.getInstance().getClan(clanId);
			if (clan != null)
			{
				removeOldPledgeCrest(clan.getCrestId());
				int newId = IdFactory.getInstance().getNextId();
				file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
				_log.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");

				Connection con = null;
				try
				{
					con = L2DatabaseFactory.getInstance().getConnection();
					PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
					statement.setInt(1, newId);
					statement.setInt(2, clan.getClanId());
					statement.executeUpdate();
					statement.close();
				}
				catch (SQLException e)
				{
					_log.log(Level.WARNING, "Could not update the crest id:" + e.getMessage(), e);
				}
				finally
				{
					L2DatabaseFactory.close(con);
				}
				clan.setCrestId(newId);
			}
			else
			{
				_log.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
				file.delete();
			}
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?")) in method public convertOldPedgeFiles() : void from class com.l2jserver.gameserver.cache.CrestCache


	private void getChildren()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_parent=?"))
		{
			ps.setInt(1, _forumId);
			try (ResultSet rs = ps.executeQuery())
			{
				while (rs.next())
				{
					Forum f = new Forum(rs.getInt("forum_id"), this);
					_children.add(f);
					ForumsBBSManager.getInstance().addForum(f);
				}
			}
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Data error on Forum (children): " + e.getMessage(), e);
		}
	}

	/**
	 *
	 */
	private void getChildren()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_parent=?");
			statement.setInt(1, _forumId);
			ResultSet result = statement.executeQuery();

			while (result.next())
			{
				Forum f = new Forum(result.getInt("forum_id"), this);
				_children.add(f);
				ForumsBBSManager.getInstance().addForum(f);
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Data error on Forum (children): " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT forum_id FROM forums WHERE forum_parent=?")) in method private getChildren() : void from class com.l2jserver.gameserver.communitybbs.BB.Forum


	public void insertIntoDb()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("INSERT INTO forums (forum_id,forum_name,forum_parent,forum_post,forum_type,forum_perm,forum_owner_id) VALUES (?,?,?,?,?,?,?)"))
		{
			ps.setInt(1, _forumId);
			ps.setString(2, _forumName);
			ps.setInt(3, _fParent.getID());
			ps.setInt(4, _forumPost);
			ps.setInt(5, _forumType);
			ps.setInt(6, _forumPerm);
			ps.setInt(7, _ownerID);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Forum to db " + e.getMessage(), e);
		}
	}

	/**
	 *
	 */
	public void insertIntoDb()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO forums (forum_id,forum_name,forum_parent,forum_post,forum_type,forum_perm,forum_owner_id) VALUES (?,?,?,?,?,?,?)");
			statement.setInt(1, _forumId);
			statement.setString(2, _forumName);
			statement.setInt(3, _fParent.getID());
			statement.setInt(4, _forumPost);
			statement.setInt(5, _forumType);
			statement.setInt(6, _forumPerm);
			statement.setInt(7, _ownerID);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Forum to db " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("INSERT INTO forums (forum_id,forum_name,forum_parent,forum_post,forum_type,forum_perm,forum_owner_id) VALUES (?,?,?,?,?,?,?)")) in method public insertIntoDb() : void from class com.l2jserver.gameserver.communitybbs.BB.Forum


	public void insertindb(CPost cp)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("INSERT INTO posts (post_id,post_owner_name,post_ownerid,post_date,post_topic_id,post_forum_id,post_txt) values (?,?,?,?,?,?,?)"))
		{
			ps.setInt(1, cp.postId);
			ps.setString(2, cp.postOwner);
			ps.setInt(3, cp.postOwnerId);
			ps.setLong(4, cp.postDate);
			ps.setInt(5, cp.postTopicId);
			ps.setInt(6, cp.postForumId);
			ps.setString(7, cp.postTxt);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
		}
	}

	public void insertindb(CPost cp)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO posts (post_id,post_owner_name,post_ownerid,post_date,post_topic_id,post_forum_id,post_txt) values (?,?,?,?,?,?,?)");
			statement.setInt(1, cp.postId);
			statement.setString(2, cp.postOwner);
			statement.setInt(3, cp.postOwnerId);
			statement.setLong(4, cp.postDate);
			statement.setInt(5, cp.postTopicId);
			statement.setInt(6, cp.postForumId);
			statement.setString(7, cp.postTxt);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("INSERT INTO posts (post_id,post_owner_name,post_ownerid,post_date,post_topic_id,post_forum_id,post_txt) values (?,?,?,?,?,?,?)")) in method public insertindb(cp CPost) : void from class com.l2jserver.gameserver.communitybbs.BB.Post


	public void deleteme(Topic t)
	{
		PostBBSManager.getInstance().delPostByTopic(t);
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("DELETE FROM posts WHERE post_forum_id=? AND post_topic_id=?"))
		{
			ps.setInt(1, t.getForumID());
			ps.setInt(2, t.getID());
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while deleting post: " + e.getMessage(), e);
		}
	}

	public void deleteme(Topic t)
	{
		PostBBSManager.getInstance().delPostByTopic(t);
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM posts WHERE post_forum_id=? AND post_topic_id=?");
			statement.setInt(1, t.getForumID());
			statement.setInt(2, t.getID());
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while deleting post: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("DELETE FROM posts WHERE post_forum_id=? AND post_topic_id=?")) in method public deleteme(t Topic) : void from class com.l2jserver.gameserver.communitybbs.BB.Post


	/**
	 * @param t
	 */
	private void load(Topic t)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC"))
		{
			ps.setInt(1, t.getForumID());
			ps.setInt(2, t.getID());
			try (ResultSet rs = ps.executeQuery())
			{
				while(rs.next())
				{
					CPost cp = new CPost();
					cp.postId = rs.getInt("post_id");
					cp.postOwner = rs.getString("post_owner_name");
					cp.postOwnerId = rs.getInt("post_ownerid");
					cp.postDate = rs.getLong("post_date");
					cp.postTopicId = rs.getInt("post_topic_id");
					cp.postForumId = rs.getInt("post_forum_id");
					cp.postTxt = rs.getString("post_txt");
					_post.add(cp);
				}
			}
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Data error on Post " + t.getForumID() + "/"+t.getID()+" : " + e.getMessage(), e);
		}
	}

	/**
	 * @param t
	 */
	private void load(Topic t)
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC");
			statement.setInt(1, t.getForumID());
			statement.setInt(2, t.getID());
			ResultSet result = statement.executeQuery();
			while(result.next())
			{
				CPost cp = new CPost();
				cp.postId = result.getInt("post_id");
				cp.postOwner = result.getString("post_owner_name");
				cp.postOwnerId = result.getInt("post_ownerid");
				cp.postDate = result.getLong("post_date");
				cp.postTopicId = result.getInt("post_topic_id");
				cp.postForumId = result.getInt("post_forum_id");
				cp.postTxt = result.getString("post_txt");
				_post.add(cp);
			}
			result.close();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Data error on Post " + t.getForumID() + "/"+t.getID()+" : " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC")) in method private load(t Topic) : void from class com.l2jserver.gameserver.communitybbs.BB.Post


	/**
	 * @param i
	 */
	public void updatetxt(int i)
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("UPDATE posts SET post_txt=? WHERE post_id=? AND post_topic_id=? AND post_forum_id=?"))
		{
			CPost cp = getCPost(i);
			ps.setString(1, cp.postTxt);
			ps.setInt(2, cp.postId);
			ps.setInt(3, cp.postTopicId);
			ps.setInt(4, cp.postForumId);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
		}
	}

	/**
	 * @param i
	 */
	public void updatetxt(int i)
	{
		Connection con = null;
		try
		{
			CPost cp = getCPost(i);
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("UPDATE posts SET post_txt=? WHERE post_id=? AND post_topic_id=? AND post_forum_id=?");
			statement.setString(1, cp.postTxt);
			statement.setInt(2, cp.postId);
			statement.setInt(3, cp.postTopicId);
			statement.setInt(4, cp.postForumId);
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("UPDATE posts SET post_txt=? WHERE post_id=? AND post_topic_id=? AND post_forum_id=?")) in method public updatetxt(i int) : void from class com.l2jserver.gameserver.communitybbs.BB.Post


	public void insertindb()
	{
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)"))
		{
			ps.setInt(1, _id);
			ps.setInt(2, _forumId);
			ps.setString(3, _topicName);
			ps.setLong(4, _date);
			ps.setString(5, _ownerName);
			ps.setInt(6, _ownerId);
			ps.setInt(7, _type);
			ps.setInt(8, _cReply);
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Topic to db " + e.getMessage(), e);
		}
	}

	/**
	 *
	 */
	public void insertindb()
	{
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)");
			statement.setInt(1, _id);
			statement.setInt(2, _forumId);
			statement.setString(3, _topicName);
			statement.setLong(4, _date);
			statement.setString(5, _ownerName);
			statement.setInt(6, _ownerId);
			statement.setInt(7, _type);
			statement.setInt(8, _cReply);
			statement.execute();
			statement.close();

		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while saving new Topic to db " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)")) in method public insertindb() : void from class com.l2jserver.gameserver.communitybbs.BB.Topic


	/**
	 * @param f
	 */
	public void deleteme(Forum f)
	{
		TopicBBSManager.getInstance().delTopic(this);
		f.rmTopicByID(getID());
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?"))
		{
			ps.setInt(1, getID());
			ps.setInt(2, f.getID());
			ps.execute();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while deleting topic: " + e.getMessage(), e);
		}
	}

	/**
	 * @param f
	 */
	public void deleteme(Forum f)
	{
		TopicBBSManager.getInstance().delTopic(this);
		f.rmTopicByID(getID());
		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?");
			statement.setInt(1, getID());
			statement.setInt(2, f.getID());
			statement.execute();
			statement.close();
		}
		catch (Exception e)
		{
			_log.log(Level.WARNING, "Error while deleting topic: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?")) in method public deleteme(f Forum) : void from class com.l2jserver.gameserver.communitybbs.BB.Topic


	public final int getIdByName(String name)
	{
		if (name == null || name.isEmpty())
			return -1;

		Iterator<Entry<Integer, String>> it = _chars.entrySet().iterator();

		Map.Entry<Integer, String> pair;
		while (it.hasNext())
		{
			pair = it.next();
			if (pair.getValue().equalsIgnoreCase(name))
				return pair.getKey();
		}

		if (Config.CACHE_CHAR_NAMES)
			return -1;

		int id = -1;
		int accessLevel = 0;

		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT charId,accesslevel FROM characters WHERE char_name=?"))
		{
			ps.setString(1, name);
			try (ResultSet rs = ps.executeQuery())
			{
				while (rs.next())
				{
					id = rs.getInt(1);
					accessLevel = rs.getInt(2);
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char name: " + e.getMessage(), e);
		}

		if (id > 0)
		{
			_chars.put(id, name);
			_accessLevels.put(id, accessLevel);
			return id;
		}

		return -1; // not found
	}

	public final int getIdByName(String name)
	{
		if (name == null || name.isEmpty())
			return -1;

		Iterator<Entry<Integer, String>> it = _chars.entrySet().iterator();

		Map.Entry<Integer, String> pair;
		while (it.hasNext())
		{
			pair = it.next();
			if (pair.getValue().equalsIgnoreCase(name))
				return pair.getKey();
		}

		if (Config.CACHE_CHAR_NAMES)
			return -1;

		int id = -1;
		int accessLevel = 0;

		Connection con = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT charId,accesslevel FROM characters WHERE char_name=?");
			statement.setString(1, name);
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{
				id = rset.getInt(1);
				accessLevel = rset.getInt(2);
			}
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char name: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}

		if (id > 0)
		{
			_chars.put(id, name);
			_accessLevels.put(id, accessLevel);
			return id;
		}

		return -1; // not found
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT charId,accesslevel FROM characters WHERE char_name=?")) in method public getIdByName(name String) : int from class com.l2jserver.gameserver.datatables.CharNameTable


	public final String getNameById(int id)
	{
		if (id <= 0)
			return null;

		String name = _chars.get(id);
		if (name != null)
			return name;

		if (Config.CACHE_CHAR_NAMES)
			return null;

		int accessLevel = 0;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT char_name,accesslevel FROM characters WHERE charId=?"))
		{
			ps.setInt(1, id);
			try (ResultSet rset = ps.executeQuery())
			{
				while (rset.next())
				{
					name = rset.getString(1);
					accessLevel = rset.getInt(2);
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char id: " + e.getMessage(), e);
		}

		if (name != null && !name.isEmpty())
		{
			_chars.put(id, name);
			_accessLevels.put(id, accessLevel);
			return name;
		}

		return null; //not found
	}

	public final String getNameById(int id)
	{
		if (id <= 0)
			return null;

		String name = _chars.get(id);
		if (name != null)
			return name;

		if (Config.CACHE_CHAR_NAMES)
			return null;

		int accessLevel = 0;
		Connection con = null;
		PreparedStatement statement = null;
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT char_name,accesslevel FROM characters WHERE charId=?");
			statement.setInt(1, id);
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{
				name = rset.getString(1);
				accessLevel = rset.getInt(2);
			}
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char id: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		if (name != null && !name.isEmpty())
		{
			_chars.put(id, name);
			_accessLevels.put(id, accessLevel);
			return name;
		}

		return null; //not found
	}

Try With Resources try(ResultSet rset=ps.executeQuery()) in method public getNameById(id int) : String from class com.l2jserver.gameserver.datatables.CharNameTable


	public synchronized boolean doesCharNameExist(String name)
	{
		boolean result = true;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?"))
		{
			ps.setString(1, name);
			try (ResultSet rs = ps.executeQuery())
			{
				result = rs.next();
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing charname: " + e.getMessage(), e);
		}
		return result;
	}

	public synchronized boolean doesCharNameExist(String name)
	{
		boolean result = true;
		Connection con = null;

		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?");
			statement.setString(1, name);
			ResultSet rset = statement.executeQuery();
			result = rset.next();
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing charname: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		return result;
	}

Try With Resources try(Connection con=L2DatabaseFactory.getInstance().getConnection(); PreparedStatement ps=con.prepareStatement("SELECT account_name FROM characters WHERE char_name=?")) in method public doesCharNameExist(name String) : boolean from class com.l2jserver.gameserver.datatables.CharNameTable


	public int accountCharNumber(String account)
	{
		int number = 0;
		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement ps = con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?"))
		{
			ps.setString(1, account);
			try (ResultSet rset = ps.executeQuery())
			{
				while (rset.next())
				{
					number = rset.getInt(1);
				}
			}
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char number: " + e.getMessage(), e);
		}
		return number;
	}

	public int accountCharNumber(String account)
	{
		Connection con = null;
		int number = 0;

		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement = con.prepareStatement("SELECT COUNT(char_name) FROM characters WHERE account_name=?");
			statement.setString(1, account);
			ResultSet rset = statement.executeQuery();
			while (rset.next())
			{
				number = rset.getInt(1);
			}
			rset.close();
			statement.close();
		}
		catch (SQLException e)
		{
			_log.log(Level.WARNING, "Could not check existing char number: " + e.getMessage(), e);
		}
		finally
		{
			L2DatabaseFactory.close(con);
		}
		return number;
	}

Try With Resources try(ResultSet rset=ps.executeQuery()) in method public accountCharNumber(account String) : int from class com.l2jserver.gameserver.datatables.CharNameTable