瀏覽代碼

BETA: Continuing with [5483] and [5520]:
* Using Statement, !PreparedStatement and !ResultSet with try-with-resource.
* Replacing !PreparedStatement with Statement where no parameters are given.
* Minor cleanup.

Zoey76 12 年之前
父節點
當前提交
91c73ec66c
共有 37 個文件被更改,包括 1233 次插入1386 次删除
  1. 52 57
      L2J_Server_BETA/java/com/l2jserver/gameserver/TradeController.java
  2. 36 29
      L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/ClanTable.java
  3. 5 4
      L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcTable.java
  4. 47 56
      L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SpawnTable.java
  5. 22 28
      L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SummonSkillsTable.java
  6. 52 48
      L2J_Server_BETA/java/com/l2jserver/gameserver/idfactory/IdFactory.java
  7. 16 19
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/AuctionManager.java
  8. 4 7
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CHSiegeManager.java
  9. 15 19
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CastleManager.java
  10. 42 42
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CastleManorManager.java
  11. 4 7
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/ClanHallManager.java
  12. 11 16
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CoupleManager.java
  13. 20 30
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CursedWeaponsManager.java
  14. 5 9
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/DimensionalRiftManager.java
  15. 9 13
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortManager.java
  16. 28 29
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortSiegeGuardManager.java
  17. 10 12
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortSiegeManager.java
  18. 173 204
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FourSepulchersManager.java
  19. 35 44
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/GrandBossManager.java
  20. 19 20
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/HellboundManager.java
  21. 27 31
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/InstanceManager.java
  22. 57 62
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/ItemsOnGroundManager.java
  23. 25 28
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MailManager.java
  24. 5 6
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MercTicketManager.java
  25. 16 19
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/RaidBossPointsManager.java
  26. 40 45
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/SiegeGuardManager.java
  27. 8 10
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/SiegeManager.java
  28. 25 34
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java
  29. 2 3
      L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/games/Lottery.java
  30. 17 17
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  31. 72 78
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java
  32. 22 24
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/ClanHall.java
  33. 35 39
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Couple.java
  34. 183 204
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Fort.java
  35. 9 9
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/FortSiege.java
  36. 83 81
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/instance/L2ItemInstance.java
  37. 2 3
      L2J_Server_BETA/java/com/l2jserver/gameserver/model/olympiad/Olympiad.java

+ 52 - 57
L2J_Server_BETA/java/com/l2jserver/gameserver/TradeController.java

@@ -33,13 +33,9 @@ import com.l2jserver.gameserver.datatables.ItemTable;
 import com.l2jserver.gameserver.model.L2TradeList;
 import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
 
-/**
- * This class ...
- * @version $Revision: 1.5.4.13 $ $Date: 2005/04/06 16:13:38 $
- */
 public class TradeController
 {
-	private static Logger _log = Logger.getLogger(TradeController.class.getName());
+	private static final Logger _log = Logger.getLogger(TradeController.class.getName());
 	
 	private int _nextListId;
 	private final Map<Integer, L2TradeList> _lists = new FastMap<>();
@@ -129,64 +125,63 @@ public class TradeController
 				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())
+				try (PreparedStatement ps = 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"))
 				{
-					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())
+					while (rset1.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();
-						}
-						
-						item.setPrice(price);
-						
-						item.setRestoreDelay(time);
-						item.setNextRestoreTime(saveTimer);
-						item.setMaxCount(maxCount);
-						
-						if (currentCount > -1)
+						ps.setString(1, String.valueOf(rset1.getInt("shop_id")));
+						try (ResultSet rset = ps.executeQuery())
 						{
-							item.setCurrentCount(currentCount);
-						}
-						else
-						{
-							item.setCurrentCount(maxCount);
+							ps.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();
+								}
+								
+								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);
 						}
-						
-						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.");
 				
 			}

+ 36 - 29
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/ClanTable.java

@@ -273,43 +273,50 @@ public class ClanTable
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM clan_data WHERE clan_id=?");
-			statement.setInt(1, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_data WHERE clan_id=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM clan_privs WHERE clan_id=?");
-			statement.setInt(1, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_privs WHERE clan_id=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM clan_skills WHERE clan_id=?");
-			statement.setInt(1, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_skills WHERE clan_id=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM clan_subpledges WHERE clan_id=?");
-			statement.setInt(1, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_subpledges WHERE clan_id=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? OR clan2=?");
-			statement.setInt(1, clanId);
-			statement.setInt(2, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_wars WHERE clan1=? OR clan2=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.setInt(2, clanId);
+				ps.execute();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM clan_notices WHERE clan_id=?");
-			statement.setInt(1, clanId);
-			statement.execute();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM clan_notices WHERE clan_id=?"))
+			{
+				ps.setInt(1, clanId);
+				ps.execute();
+			}
 			
 			if (castleId != 0)
 			{
-				statement = con.prepareStatement("UPDATE castle SET taxPercent = 0 WHERE id = ?");
-				statement.setInt(1, castleId);
-				statement.execute();
-				statement.close();
+				try (PreparedStatement ps = con.prepareStatement("UPDATE castle SET taxPercent = 0 WHERE id = ?"))
+				{
+					ps.setInt(1, castleId);
+					ps.execute();
+				}
 			}
 			
 			if (fortId != 0)

+ 5 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcTable.java

@@ -331,10 +331,11 @@ public class NpcTable
 			sbQuery.append(" WHERE ");
 			sbQuery.append(key);
 			sbQuery.append(" = ?");
-			final PreparedStatement statement = con.prepareStatement(sbQuery.toString());
-			statement.setInt(1, npcId);
-			updated = statement.executeUpdate();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement(sbQuery.toString()))
+			{
+				ps.setInt(1, npcId);
+				updated = ps.executeUpdate();
+			}
 		}
 		return updated;
 	}

+ 47 - 56
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SpawnTable.java

@@ -17,6 +17,7 @@ package com.l2jserver.gameserver.datatables;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -31,13 +32,11 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
 
 /**
- * This class ...
  * @author Nightmare
- * @version $Revision: 1.5.2.6.2.7 $ $Date: 2005/03/27 15:29:18 $
  */
 public class SpawnTable
 {
-	private static Logger _log = Logger.getLogger(SpawnTable.class.getName());
+	private static final Logger _log = Logger.getLogger(SpawnTable.class.getName());
 	
 	private final FastSet<L2Spawn> _spawntable = new FastSet<>();
 	private int _npcSpawnCount;
@@ -59,17 +58,15 @@ public class SpawnTable
 	
 	private void fillSpawnTable()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM spawnlist"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM spawnlist");
-			ResultSet rset = statement.executeQuery();
-			
 			L2Spawn spawnDat;
 			L2NpcTemplate template1;
-			
-			while (rset.next())
+			while (rs.next())
 			{
-				template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
+				template1 = NpcTable.getInstance().getTemplate(rs.getInt("npc_templateid"));
 				if (template1 != null)
 				{
 					if (template1.isType("L2SiegeGuard"))
@@ -87,16 +84,16 @@ public class SpawnTable
 					else
 					{
 						spawnDat = new L2Spawn(template1);
-						spawnDat.setAmount(rset.getInt("count"));
-						spawnDat.setLocx(rset.getInt("locx"));
-						spawnDat.setLocy(rset.getInt("locy"));
-						spawnDat.setLocz(rset.getInt("locz"));
-						spawnDat.setHeading(rset.getInt("heading"));
-						spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
-						int loc_id = rset.getInt("loc_id");
+						spawnDat.setAmount(rs.getInt("count"));
+						spawnDat.setLocx(rs.getInt("locx"));
+						spawnDat.setLocy(rs.getInt("locy"));
+						spawnDat.setLocz(rs.getInt("locz"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
+						int loc_id = rs.getInt("loc_id");
 						spawnDat.setLocation(loc_id);
 						
-						switch (rset.getInt("periodOfDay"))
+						switch (rs.getInt("periodOfDay"))
 						{
 							case 0: // default
 								_npcSpawnCount += spawnDat.init();
@@ -116,11 +113,9 @@ public class SpawnTable
 				}
 				else
 				{
-					_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rset.getInt("npc_templateid") + ".");
+					_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rs.getInt("npc_templateid") + ".");
 				}
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -132,17 +127,15 @@ public class SpawnTable
 		
 		if (Config.CUSTOM_SPAWNLIST_TABLE)
 		{
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				Statement ps = con.createStatement();
+				ResultSet rs = ps.executeQuery("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM custom_spawnlist"))
 			{
-				PreparedStatement statement = con.prepareStatement("SELECT count, npc_templateid, locx, locy, locz, heading, respawn_delay, loc_id, periodOfDay FROM custom_spawnlist");
-				ResultSet rset = statement.executeQuery();
-				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
-				
-				while (rset.next())
+				while (rs.next())
 				{
-					template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
+					template1 = NpcTable.getInstance().getTemplate(rs.getInt("npc_templateid"));
 					if (template1 != null)
 					{
 						if (template1.isType("L2SiegeGuard"))
@@ -160,17 +153,17 @@ public class SpawnTable
 						else
 						{
 							spawnDat = new L2Spawn(template1);
-							spawnDat.setAmount(rset.getInt("count"));
-							spawnDat.setLocx(rset.getInt("locx"));
-							spawnDat.setLocy(rset.getInt("locy"));
-							spawnDat.setLocz(rset.getInt("locz"));
-							spawnDat.setHeading(rset.getInt("heading"));
-							spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
+							spawnDat.setAmount(rs.getInt("count"));
+							spawnDat.setLocx(rs.getInt("locx"));
+							spawnDat.setLocy(rs.getInt("locy"));
+							spawnDat.setLocz(rs.getInt("locz"));
+							spawnDat.setHeading(rs.getInt("heading"));
+							spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
 							spawnDat.setCustom(true);
-							int loc_id = rset.getInt("loc_id");
+							int loc_id = rs.getInt("loc_id");
 							spawnDat.setLocation(loc_id);
 							
-							switch (rset.getInt("periodOfDay"))
+							switch (rs.getInt("periodOfDay"))
 							{
 								case 0: // default
 									_customSpawnCount += spawnDat.init();
@@ -190,11 +183,9 @@ public class SpawnTable
 					}
 					else
 					{
-						_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rset.getInt("npc_templateid") + ".");
+						_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rs.getInt("npc_templateid") + ".");
 					}
 				}
-				rset.close();
-				statement.close();
 			}
 			catch (Exception e)
 			{
@@ -229,17 +220,17 @@ public class SpawnTable
 			}
 			
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("INSERT INTO " + spawnTable + "(count,npc_templateid,locx,locy,locz,heading,respawn_delay,loc_id) values(?,?,?,?,?,?,?,?)"))
+				PreparedStatement insert = con.prepareStatement("INSERT INTO " + spawnTable + "(count,npc_templateid,locx,locy,locz,heading,respawn_delay,loc_id) values(?,?,?,?,?,?,?,?)"))
 			{
-				statement.setInt(1, spawn.getAmount());
-				statement.setInt(2, spawn.getNpcid());
-				statement.setInt(3, spawn.getLocx());
-				statement.setInt(4, spawn.getLocy());
-				statement.setInt(5, spawn.getLocz());
-				statement.setInt(6, spawn.getHeading());
-				statement.setInt(7, spawn.getRespawnDelay() / 1000);
-				statement.setInt(8, spawn.getLocation());
-				statement.execute();
+				insert.setInt(1, spawn.getAmount());
+				insert.setInt(2, spawn.getNpcid());
+				insert.setInt(3, spawn.getLocx());
+				insert.setInt(4, spawn.getLocy());
+				insert.setInt(5, spawn.getLocz());
+				insert.setInt(6, spawn.getHeading());
+				insert.setInt(7, spawn.getRespawnDelay() / 1000);
+				insert.setInt(8, spawn.getLocation());
+				insert.execute();
 			}
 			catch (Exception e)
 			{
@@ -259,14 +250,14 @@ public class SpawnTable
 		if (updateDb)
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("DELETE FROM " + (spawn.isCustom() ? "custom_spawnlist" : "spawnlist") + " WHERE locx=? AND locy=? AND locz=? AND npc_templateid=? AND heading=?"))
+				PreparedStatement delete = con.prepareStatement("DELETE FROM " + (spawn.isCustom() ? "custom_spawnlist" : "spawnlist") + " WHERE locx=? AND locy=? AND locz=? AND npc_templateid=? AND heading=?"))
 			{
-				statement.setInt(1, spawn.getLocx());
-				statement.setInt(2, spawn.getLocy());
-				statement.setInt(3, spawn.getLocz());
-				statement.setInt(4, spawn.getNpcid());
-				statement.setInt(5, spawn.getHeading());
-				statement.execute();
+				delete.setInt(1, spawn.getLocx());
+				delete.setInt(2, spawn.getLocy());
+				delete.setInt(3, spawn.getLocz());
+				delete.setInt(4, spawn.getNpcid());
+				delete.setInt(5, spawn.getHeading());
+				delete.execute();
 			}
 			catch (Exception e)
 			{

+ 22 - 28
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/SummonSkillsTable.java

@@ -17,6 +17,7 @@ package com.l2jserver.gameserver.datatables;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -43,40 +44,33 @@ public class SummonSkillsTable
 		_skillTrees.clear();
 		int npcId = 0;
 		int count = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT id FROM npc WHERE type IN ('L2Pet','L2BabyPet','L2SiegeSummon') ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id FROM npc WHERE type IN ('L2Pet','L2BabyPet','L2SiegeSummon') ORDER BY id");
-			ResultSet petlist = statement.executeQuery();
 			Map<Integer, L2PetSkillLearn> map;
-			L2PetSkillLearn skillLearn;
-			
-			PreparedStatement statement2 = con.prepareStatement("SELECT minLvl, skillId, skillLvl FROM pets_skills where templateId=? ORDER BY skillId, skillLvl");
-			while (petlist.next())
+			try (PreparedStatement ps2 = con.prepareStatement("SELECT minLvl, skillId, skillLvl FROM pets_skills where templateId=? ORDER BY skillId, skillLvl"))
 			{
-				map = new HashMap<>();
-				npcId = petlist.getInt("id");
-				statement2.setInt(1, npcId);
-				ResultSet skilltree = statement2.executeQuery();
-				statement2.clearParameters();
-				
-				while (skilltree.next())
+				while (rs.next())
 				{
-					int id = skilltree.getInt("skillId");
-					int lvl = skilltree.getInt("skillLvl");
-					int minLvl = skilltree.getInt("minLvl");
-					
-					skillLearn = new L2PetSkillLearn(id, lvl, minLvl);
-					map.put(SkillTable.getSkillHashCode(id, lvl + 1), skillLearn);
+					map = new HashMap<>();
+					npcId = rs.getInt("id");
+					ps2.setInt(1, npcId);
+					try (ResultSet skilltree = ps2.executeQuery())
+					{
+						while (skilltree.next())
+						{
+							int id = skilltree.getInt("skillId");
+							int lvl = skilltree.getInt("skillLvl");
+							map.put(SkillTable.getSkillHashCode(id, lvl + 1), new L2PetSkillLearn(id, lvl, skilltree.getInt("minLvl")));
+						}
+						_skillTrees.put(npcId, map);
+					}
+					ps2.clearParameters();
+					count += map.size();
+					_log.fine(getClass().getSimpleName() + ": skill tree for pet " + npcId + " has " + map.size() + " skills");
 				}
-				_skillTrees.put(npcId, map);
-				skilltree.close();
-				
-				count += map.size();
-				_log.fine(getClass().getSimpleName() + ": skill tree for pet " + npcId + " has " + map.size() + " skills");
 			}
-			statement2.close();
-			petlist.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 52 - 48
L2J_Server_BETA/java/com/l2jserver/gameserver/idfactory/IdFactory.java

@@ -327,75 +327,79 @@ public abstract class IdFactory
 	 */
 	protected final int[] extractUsedObjectIDTable() throws Exception
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement())
 		{
-			Statement statement = null;
-			ResultSet rset = null;
-			
-			statement = con.createStatement();
 			final TIntArrayList temp = new TIntArrayList();
-			
-			rset = statement.executeQuery("SELECT COUNT(*) FROM characters");
-			rset.next();
-			temp.ensureCapacity(rset.getInt(1));
-			rset.close();
-			
-			rset = statement.executeQuery("SELECT charId FROM characters");
-			while (rset.next())
+			try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM characters"))
 			{
-				temp.add(rset.getInt(1));
+				rs.next();
+				temp.ensureCapacity(rs.getInt(1));
 			}
-			rset.close();
 			
-			rset = statement.executeQuery("SELECT COUNT(*) FROM items");
-			rset.next();
-			temp.ensureCapacity(temp.size() + rset.getInt(1));
-			rset.close();
+			try (ResultSet rs = s.executeQuery("SELECT charId FROM characters"))
+			{
+				while (rs.next())
+				{
+					temp.add(rs.getInt(1));
+				}
+			}
 			
-			rset = statement.executeQuery("SELECT object_id FROM items");
-			while (rset.next())
+			try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM items"))
 			{
-				temp.add(rset.getInt(1));
+				rs.next();
+				temp.ensureCapacity(temp.size() + rs.getInt(1));
 			}
-			rset.close();
 			
-			rset = statement.executeQuery("SELECT COUNT(*) FROM clan_data");
-			rset.next();
-			temp.ensureCapacity(temp.size() + rset.getInt(1));
-			rset.close();
+			try (ResultSet rs = s.executeQuery("SELECT object_id FROM items"))
+			{
+				while (rs.next())
+				{
+					temp.add(rs.getInt(1));
+				}
+			}
 			
-			rset = statement.executeQuery("SELECT clan_id FROM clan_data");
-			while (rset.next())
+			try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM clan_data"))
 			{
-				temp.add(rset.getInt(1));
+				rs.next();
+				temp.ensureCapacity(temp.size() + rs.getInt(1));
 			}
-			rset.close();
 			
-			rset = statement.executeQuery("SELECT COUNT(*) FROM itemsonground");
-			rset.next();
-			temp.ensureCapacity(temp.size() + rset.getInt(1));
-			rset.close();
+			try (ResultSet rs = s.executeQuery("SELECT clan_id FROM clan_data"))
+			{
+				while (rs.next())
+				{
+					temp.add(rs.getInt(1));
+				}
+			}
 			
-			rset = statement.executeQuery("SELECT object_id FROM itemsonground");
-			while (rset.next())
+			try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM itemsonground"))
 			{
-				temp.add(rset.getInt(1));
+				rs.next();
+				temp.ensureCapacity(temp.size() + rs.getInt(1));
 			}
-			rset.close();
 			
-			rset = statement.executeQuery("SELECT COUNT(*) FROM messages");
-			rset.next();
-			temp.ensureCapacity(temp.size() + rset.getInt(1));
-			rset.close();
+			try (ResultSet rs = s.executeQuery("SELECT object_id FROM itemsonground"))
+			{
+				while (rs.next())
+				{
+					temp.add(rs.getInt(1));
+				}
+			}
 			
-			rset = statement.executeQuery("SELECT messageId FROM messages");
-			while (rset.next())
+			try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM messages"))
 			{
-				temp.add(rset.getInt(1));
+				rs.next();
+				temp.ensureCapacity(temp.size() + rs.getInt(1));
 			}
-			rset.close();
-			statement.close();
 			
+			try (ResultSet rs = s.executeQuery("SELECT messageId FROM messages"))
+			{
+				while (rs.next())
+				{
+					temp.add(rs.getInt(1));
+				}
+			}
 			temp.sort();
 			return temp.toArray();
 		}

+ 16 - 19
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/AuctionManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Level;
@@ -83,11 +83,6 @@ public class AuctionManager
 	};
 	// @formatter:on
 	
-	public static final AuctionManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
 	protected AuctionManager()
 	{
 		load();
@@ -101,17 +96,15 @@ public class AuctionManager
 	
 	private final void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT id FROM auction ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id FROM auction ORDER BY id");
-			ResultSet rs = statement.executeQuery();
 			while (rs.next())
 			{
 				_auctions.add(new Auction(rs.getInt("id")));
 			}
-			rs.close();
-			statement.close();
-			_log.info(getClass().getSimpleName() + ": Loaded: " + getAuctions().size() + " auction(s)");
+			_log.info(getClass().getSimpleName() + ": Loaded: " + _auctions.size() + " auction(s)");
 		}
 		catch (Exception e)
 		{
@@ -124,7 +117,7 @@ public class AuctionManager
 		int index = getAuctionIndex(auctionId);
 		if (index >= 0)
 		{
-			return getAuctions().get(index);
+			return _auctions.get(index);
 		}
 		return null;
 	}
@@ -132,9 +125,9 @@ public class AuctionManager
 	public final int getAuctionIndex(int auctionId)
 	{
 		Auction auction;
-		for (int i = 0; i < getAuctions().size(); i++)
+		for (int i = 0; i < _auctions.size(); i++)
 		{
-			auction = getAuctions().get(i);
+			auction = _auctions.get(i);
 			if ((auction != null) && (auction.getId() == auctionId))
 			{
 				return i;
@@ -168,11 +161,10 @@ public class AuctionManager
 			return;
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement())
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO `auction` VALUES " + ITEM_INIT_DATA[i]);
-			statement.execute();
-			statement.close();
+			s.executeUpdate("INSERT INTO `auction` VALUES " + ITEM_INIT_DATA[i]);
 			_auctions.add(new Auction(id));
 			_log.info(getClass().getSimpleName() + ": Created auction for ClanHall: " + id);
 		}
@@ -182,6 +174,11 @@ public class AuctionManager
 		}
 	}
 	
+	public static final AuctionManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final AuctionManager _instance = new AuctionManager();

+ 4 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CHSiegeManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.Map;
 import java.util.logging.Logger;
 
@@ -51,11 +51,10 @@ public final class CHSiegeManager
 	
 	private final void loadClanHalls()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery(SQL_LOAD_HALLS))
 		{
-			PreparedStatement statement = con.prepareStatement(SQL_LOAD_HALLS);
-			ResultSet rs = statement.executeQuery();
-			
 			_siegableHalls.clear();
 			
 			while (rs.next())
@@ -77,8 +76,6 @@ public final class CHSiegeManager
 				ClanHallManager.addClanHall(hall);
 			}
 			_log.info(getClass().getSimpleName() + ": Loaded " + _siegableHalls.size() + " conquerable clan halls.");
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 15 - 19
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CastleManager.java

@@ -17,6 +17,7 @@ package com.l2jserver.gameserver.instancemanager;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -35,12 +36,7 @@ import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 
 public class CastleManager implements InstanceListManager
 {
-	protected static final Logger _log = Logger.getLogger(CastleManager.class.getName());
-	
-	public static final CastleManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
+	private static final Logger _log = Logger.getLogger(CastleManager.class.getName());
 	
 	private List<Castle> _castles;
 	
@@ -266,13 +262,12 @@ public class CastleManager implements InstanceListManager
 				}
 			}
 			// else offline-player circlet removal
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement ps = con.prepareStatement("DELETE FROM items WHERE owner_id = ? and item_id = ?"))
 			{
-				PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE owner_id = ? and item_id = ?");
-				statement.setInt(1, member.getObjectId());
-				statement.setInt(2, circletId);
-				statement.execute();
-				statement.close();
+				ps.setInt(1, member.getObjectId());
+				ps.setInt(2, circletId);
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -284,18 +279,14 @@ public class CastleManager implements InstanceListManager
 	@Override
 	public void loadInstances()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT id FROM castle ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id FROM castle ORDER BY id");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				getCastles().add(new Castle(rs.getInt("id")));
 			}
-			rs.close();
-			statement.close();
-			
 			_log.info(getClass().getSimpleName() + ": Loaded: " + getCastles().size() + " castles");
 		}
 		catch (Exception e)
@@ -318,6 +309,11 @@ public class CastleManager implements InstanceListManager
 		}
 	}
 	
+	public static final CastleManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final CastleManager _instance = new CastleManager();

+ 42 - 42
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CastleManorManager.java

@@ -41,7 +41,7 @@ import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.util.Rnd;
 
 /**
- * Class For Castle Manor Manager Load manor data from DB Update/Reload/Delete Handles all schedule for manor
+ * Class for Castle Manor Manager load manor data from DB update/reload/delete, handles all schedule for manor.
  * @author l3x
  */
 public class CastleManorManager
@@ -70,11 +70,6 @@ public class CastleManorManager
 	protected ScheduledFuture<?> _scheduledMaintenanceEnd;
 	protected ScheduledFuture<?> _scheduledNextPeriodapprove;
 	
-	public static final CastleManorManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
 	public static class CropProcure
 	{
 		final int _cropId;
@@ -207,10 +202,10 @@ public class CastleManorManager
 	
 	private void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statementProduction = con.prepareStatement(CASTLE_MANOR_LOAD_PRODUCTION);
-			PreparedStatement statementProcure = con.prepareStatement(CASTLE_MANOR_LOAD_PROCURE);
+			PreparedStatement statementProcure = con.prepareStatement(CASTLE_MANOR_LOAD_PROCURE))
+		{
 			for (Castle castle : CastleManager.getInstance().getCastles())
 			{
 				FastList<SeedProduction> production = new FastList<>();
@@ -220,25 +215,26 @@ public class CastleManorManager
 				
 				// restore seed production info
 				statementProduction.setInt(1, castle.getCastleId());
-				ResultSet rs = statementProduction.executeQuery();
-				statementProduction.clearParameters();
-				while (rs.next())
+				try (ResultSet rs = statementProduction.executeQuery())
 				{
-					int seedId = rs.getInt("seed_id");
-					int canProduce = rs.getInt("can_produce");
-					int startProduce = rs.getInt("start_produce");
-					int price = rs.getInt("seed_price");
-					int period = rs.getInt("period");
-					if (period == PERIOD_CURRENT)
-					{
-						production.add(new SeedProduction(seedId, canProduce, price, startProduce));
-					}
-					else
+					statementProduction.clearParameters();
+					while (rs.next())
 					{
-						productionNext.add(new SeedProduction(seedId, canProduce, price, startProduce));
+						int seedId = rs.getInt("seed_id");
+						int canProduce = rs.getInt("can_produce");
+						int startProduce = rs.getInt("start_produce");
+						int price = rs.getInt("seed_price");
+						int period = rs.getInt("period");
+						if (period == PERIOD_CURRENT)
+						{
+							production.add(new SeedProduction(seedId, canProduce, price, startProduce));
+						}
+						else
+						{
+							productionNext.add(new SeedProduction(seedId, canProduce, price, startProduce));
+						}
 					}
 				}
-				rs.close();
 				
 				castle.setSeedProduction(production, PERIOD_CURRENT);
 				castle.setSeedProduction(productionNext, PERIOD_NEXT);
@@ -246,26 +242,27 @@ public class CastleManorManager
 				// restore procure info
 				
 				statementProcure.setInt(1, castle.getCastleId());
-				rs = statementProcure.executeQuery();
-				statementProcure.clearParameters();
-				while (rs.next())
+				try (ResultSet rs = statementProcure.executeQuery())
 				{
-					int cropId = rs.getInt("crop_id");
-					int canBuy = rs.getInt("can_buy");
-					int startBuy = rs.getInt("start_buy");
-					int rewardType = rs.getInt("reward_type");
-					int price = rs.getInt("price");
-					int period = rs.getInt("period");
-					if (period == PERIOD_CURRENT)
-					{
-						procure.add(new CropProcure(cropId, canBuy, rewardType, startBuy, price));
-					}
-					else
+					statementProcure.clearParameters();
+					while (rs.next())
 					{
-						procureNext.add(new CropProcure(cropId, canBuy, rewardType, startBuy, price));
+						int cropId = rs.getInt("crop_id");
+						int canBuy = rs.getInt("can_buy");
+						int startBuy = rs.getInt("start_buy");
+						int rewardType = rs.getInt("reward_type");
+						int price = rs.getInt("price");
+						int period = rs.getInt("period");
+						if (period == PERIOD_CURRENT)
+						{
+							procure.add(new CropProcure(cropId, canBuy, rewardType, startBuy, price));
+						}
+						else
+						{
+							procureNext.add(new CropProcure(cropId, canBuy, rewardType, startBuy, price));
+						}
 					}
 				}
-				rs.close();
 				
 				castle.setCropProcure(procure, PERIOD_CURRENT);
 				castle.setCropProcure(procureNext, PERIOD_NEXT);
@@ -275,8 +272,6 @@ public class CastleManorManager
 					_log.info(getClass().getSimpleName() + ": " + castle.getName() + ": Data loaded");
 				}
 			}
-			statementProduction.close();
-			statementProcure.close();
 		}
 		catch (Exception e)
 		{
@@ -620,6 +615,11 @@ public class CastleManorManager
 		}
 	}
 	
+	public static final CastleManorManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final CastleManorManager _instance = new CastleManorManager();

+ 4 - 7
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/ClanHallManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -63,11 +63,11 @@ public final class ClanHallManager
 	/** Load All Clan Hall */
 	private final void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM clanhall ORDER BY id"))
 		{
 			int id, ownerId, lease;
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM clanhall ORDER BY id");
-			ResultSet rs = statement.executeQuery();
 			while (rs.next())
 			{
 				StatsSet set = new StatsSet();
@@ -102,9 +102,6 @@ public final class ClanHallManager
 					AuctionManager.getInstance().initNPC(id);
 				}
 			}
-			
-			rs.close();
-			statement.close();
 			_log.info(getClass().getSimpleName() + ": Loaded: " + getClanHalls().size() + " clan halls");
 			_log.info(getClass().getSimpleName() + ": Loaded: " + getFreeClanHalls().size() + " free clan halls");
 			_loaded = true;

+ 11 - 16
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CoupleManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -34,18 +34,13 @@ public class CoupleManager
 {
 	private static final Logger _log = Logger.getLogger(CoupleManager.class.getName());
 	
+	private FastList<Couple> _couples;
+	
 	protected CoupleManager()
 	{
 		load();
 	}
 	
-	public static final CoupleManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
-	private FastList<Couple> _couples;
-	
 	public void reload()
 	{
 		getCouples().clear();
@@ -54,19 +49,14 @@ public class CoupleManager
 	
 	private final void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement ps = con.createStatement();
+			ResultSet rs = ps.executeQuery("SELECT id FROM mods_wedding ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id FROM mods_wedding ORDER BY id");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				getCouples().add(new Couple(rs.getInt("id")));
 			}
-			
-			rs.close();
-			statement.close();
-			
 			_log.info(getClass().getSimpleName() + ": Loaded: " + getCouples().size() + " couples(s)");
 		}
 		catch (Exception e)
@@ -154,6 +144,11 @@ public class CoupleManager
 		return _couples;
 	}
 	
+	public static final CoupleManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final CoupleManager _instance = new CoupleManager();

+ 20 - 30
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/CursedWeaponsManager.java

@@ -19,6 +19,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -169,31 +170,22 @@ public class CursedWeaponsManager
 	
 	private final void restore()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT itemId, charId, playerKarma, playerPkKills, nbKills, endTime FROM cursed_weapons"))
 		{
 			// Retrieve the L2PcInstance from the characters table of the database
-			PreparedStatement statement = con.prepareStatement("SELECT itemId, charId, playerKarma, playerPkKills, nbKills, endTime FROM cursed_weapons");
-			ResultSet rset = statement.executeQuery();
-			while (rset.next())
+			CursedWeapon cw;
+			while (rs.next())
 			{
-				int itemId = rset.getInt("itemId");
-				int playerId = rset.getInt("charId");
-				int playerKarma = rset.getInt("playerKarma");
-				int playerPkKills = rset.getInt("playerPkKills");
-				int nbKills = rset.getInt("nbKills");
-				long endTime = rset.getLong("endTime");
-				
-				CursedWeapon cw = _cursedWeapons.get(itemId);
-				cw.setPlayerId(playerId);
-				cw.setPlayerKarma(playerKarma);
-				cw.setPlayerPkKills(playerPkKills);
-				cw.setNbKills(nbKills);
-				cw.setEndTime(endTime);
+				cw = _cursedWeapons.get(rs.getInt("itemId"));
+				cw.setPlayerId(rs.getInt("charId"));
+				cw.setPlayerKarma(rs.getInt("playerKarma"));
+				cw.setPlayerPkKills(rs.getInt("playerPkKills"));
+				cw.setNbKills(rs.getInt("nbKills"));
+				cw.setEndTime(rs.getLong("endTime"));
 				cw.reActivate();
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -213,7 +205,7 @@ public class CursedWeaponsManager
 			// or a lost-child entry in the cursed weapons table, without a corresponding one in items...
 			
 			// Retrieve the L2PcInstance from the characters table of the database
-			try (PreparedStatement statement = con.prepareStatement("SELECT owner_id FROM items WHERE item_id=?"))
+			try (PreparedStatement ps = con.prepareStatement("SELECT owner_id FROM items WHERE item_id=?"))
 			{
 				for (CursedWeapon cw : _cursedWeapons.values())
 				{
@@ -224,8 +216,8 @@ public class CursedWeaponsManager
 					
 					// Do an item check to be sure that the cursed weapon isn't hold by someone
 					int itemId = cw.getItemId();
-					statement.setInt(1, itemId);
-					try (ResultSet rset = statement.executeQuery())
+					ps.setInt(1, itemId);
+					try (ResultSet rset = ps.executeQuery())
 					{
 						if (rset.next())
 						{
@@ -259,7 +251,7 @@ public class CursedWeaponsManager
 							removeFromDb(itemId);
 						}
 					}
-					statement.clearParameters();
+					ps.clearParameters();
 				}
 			}
 		}
@@ -379,13 +371,11 @@ public class CursedWeaponsManager
 	
 	public static void removeFromDb(int itemId)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?"))
 		{
-			// Delete datas
-			PreparedStatement statement = con.prepareStatement("DELETE FROM cursed_weapons WHERE itemId = ?");
-			statement.setInt(1, itemId);
-			statement.executeUpdate();
-			statement.close();
+			ps.setInt(1, itemId);
+			ps.executeUpdate();
 		}
 		catch (SQLException e)
 		{

+ 5 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/DimensionalRiftManager.java

@@ -18,8 +18,8 @@ import java.awt.Polygon;
 import java.awt.Shape;
 import java.io.File;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -49,7 +49,7 @@ import com.l2jserver.util.Rnd;
 import gnu.trove.map.hash.TByteObjectHashMap;
 
 /**
- * Thanks to L2Fortress and balancer.ru - kombat
+ * @author kombat
  */
 public class DimensionalRiftManager
 {
@@ -77,11 +77,10 @@ public class DimensionalRiftManager
 	
 	private void loadRooms()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM dimensional_rift"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM dimensional_rift");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				// 0 waiting room, 1 recruit, 2 soldier, 3 officer, 4 captain , 5 commander, 6 hero
@@ -107,9 +106,6 @@ public class DimensionalRiftManager
 				
 				_rooms.get(type).put(room_id, new DimensionalRiftRoom(type, room_id, xMin, xMax, yMin, yMax, z1, z2, xT, yT, zT, isBossRoom));
 			}
-			
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 9 - 13
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -33,11 +33,6 @@ public class FortManager implements InstanceListManager
 {
 	protected static final Logger _log = Logger.getLogger(FortManager.class.getName());
 	
-	public static final FortManager getInstance()
-	{
-		return SingletonHolder._instance;
-	}
-	
 	private List<Fort> _forts;
 	
 	public final int findNearestFortIndex(L2Object obj)
@@ -168,19 +163,15 @@ public class FortManager implements InstanceListManager
 	@Override
 	public void loadInstances()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT id FROM fort ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id FROM fort ORDER BY id");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				getForts().add(new Fort(rs.getInt("id")));
 			}
 			
-			rs.close();
-			statement.close();
-			
 			_log.info(getClass().getSimpleName() + ": Loaded: " + getForts().size() + " fortress");
 			for (Fort fort : getForts())
 			{
@@ -207,6 +198,11 @@ public class FortManager implements InstanceListManager
 		}
 	}
 	
+	public static final FortManager getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
 	private static class SingletonHolder
 	{
 		protected static final FortManager _instance = new FortManager();

+ 28 - 29
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortSiegeGuardManager.java

@@ -106,40 +106,39 @@ public class FortSiegeGuardManager
 	void loadSiegeGuard()
 	{
 		_siegeGuards.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM fort_siege_guards Where fortId = ? "))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_siege_guards Where fortId = ? ");
-			statement.setInt(1, getFort().getFortId());
-			ResultSet rs = statement.executeQuery();
-			
-			L2Spawn spawn1;
-			L2NpcTemplate template1;
-			_siegeGuardsSpawns = new FastList<>();
-			while (rs.next())
+			ps.setInt(1, getFort().getFortId());
+			try (ResultSet rs = ps.executeQuery())
 			{
-				int fortId = rs.getInt("fortId");
-				template1 = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
-				if (template1 != null)
-				{
-					spawn1 = new L2Spawn(template1);
-					spawn1.setAmount(1);
-					spawn1.setLocx(rs.getInt("x"));
-					spawn1.setLocy(rs.getInt("y"));
-					spawn1.setLocz(rs.getInt("z"));
-					spawn1.setHeading(rs.getInt("heading"));
-					spawn1.setRespawnDelay(rs.getInt("respawnDelay"));
-					spawn1.setLocation(0);
-					
-					_siegeGuardsSpawns.add(spawn1);
-				}
-				else
+				L2Spawn spawn1;
+				L2NpcTemplate template1;
+				_siegeGuardsSpawns = new FastList<>();
+				while (rs.next())
 				{
-					_log.warning("Missing npc data in npc table for id: " + rs.getInt("npcId"));
+					int fortId = rs.getInt("fortId");
+					template1 = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
+					if (template1 != null)
+					{
+						spawn1 = new L2Spawn(template1);
+						spawn1.setAmount(1);
+						spawn1.setLocx(rs.getInt("x"));
+						spawn1.setLocy(rs.getInt("y"));
+						spawn1.setLocz(rs.getInt("z"));
+						spawn1.setHeading(rs.getInt("heading"));
+						spawn1.setRespawnDelay(rs.getInt("respawnDelay"));
+						spawn1.setLocation(0);
+						
+						_siegeGuardsSpawns.add(spawn1);
+					}
+					else
+					{
+						_log.warning("Missing npc data in npc table for id: " + rs.getInt("npcId"));
+					}
+					_siegeGuards.put(fortId, _siegeGuardsSpawns);
 				}
-				_siegeGuards.put(fortId, _siegeGuardsSpawns);
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 10 - 12
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FortSiegeManager.java

@@ -129,21 +129,19 @@ public class FortSiegeManager
 		}
 		
 		boolean register = false;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT clan_id FROM fortsiege_clans where clan_id=? and fort_id=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM fortsiege_clans where clan_id=? and fort_id=?");
-			statement.setInt(1, clan.getClanId());
-			statement.setInt(2, fortid);
-			ResultSet rs = statement.executeQuery();
-			
-			while (rs.next())
+			ps.setInt(1, clan.getClanId());
+			ps.setInt(2, fortid);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				register = true;
-				break;
+				while (rs.next())
+				{
+					register = true;
+					break;
+				}
 			}
-			
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 173 - 204
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/FourSepulchersManager.java

@@ -425,39 +425,37 @@ public class FourSepulchersManager
 	{
 		_mysteriousBoxSpawns.clear();
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY id");
-			statement.setInt(1, 0);
-			ResultSet rset = statement.executeQuery();
-			
-			L2Spawn spawnDat;
-			L2NpcTemplate template1;
-			
-			while (rset.next())
+			ps.setInt(1, 0);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				template1 = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
-				if (template1 != null)
-				{
-					spawnDat = new L2Spawn(template1);
-					spawnDat.setAmount(rset.getInt("count"));
-					spawnDat.setLocx(rset.getInt("locx"));
-					spawnDat.setLocy(rset.getInt("locy"));
-					spawnDat.setLocz(rset.getInt("locz"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
-					SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-					int keyNpcId = rset.getInt("key_npc_id");
-					_mysteriousBoxSpawns.put(keyNpcId, spawnDat);
-				}
-				else
+				
+				L2Spawn spawnDat;
+				L2NpcTemplate template1;
+				while (rs.next())
 				{
-					_log.warning("FourSepulchersManager.LoadMysteriousBox: Data missing in NPC table for ID: " + rset.getInt("npc_templateid") + ".");
+					template1 = NpcTable.getInstance().getTemplate(rs.getInt("npc_templateid"));
+					if (template1 != null)
+					{
+						spawnDat = new L2Spawn(template1);
+						spawnDat.setAmount(rs.getInt("count"));
+						spawnDat.setLocx(rs.getInt("locx"));
+						spawnDat.setLocy(rs.getInt("locy"));
+						spawnDat.setLocz(rs.getInt("locz"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
+						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+						int keyNpcId = rs.getInt("key_npc_id");
+						_mysteriousBoxSpawns.put(keyNpcId, spawnDat);
+					}
+					else
+					{
+						_log.warning("FourSepulchersManager.LoadMysteriousBox: Data missing in NPC table for ID: " + rs.getInt("npc_templateid") + ".");
+					}
 				}
 			}
-			
-			rset.close();
-			statement.close();
 			_log.info(getClass().getSimpleName() + ": loaded " + _mysteriousBoxSpawns.size() + " Mysterious-Box spawns.");
 		}
 		catch (Exception e)
@@ -471,7 +469,7 @@ public class FourSepulchersManager
 	{
 		L2Spawn spawnDat;
 		L2NpcTemplate template;
-		
+		// Zoey76: TODO: Replace iteration over keys with iteration over entries to avoid calling get method inside the loop.
 		for (int keyNpcId : _keyBoxNpc.keys())
 		{
 			try
@@ -506,128 +504,112 @@ public class FourSepulchersManager
 		_physicalMonsters.clear();
 		
 		int loaded = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
 		{
-			PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
-			statement1.setInt(1, 1);
-			ResultSet rset1 = statement1.executeQuery();
-			
-			PreparedStatement statement2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where key_npc_id = ? and spawntype = ? ORDER BY id");
-			while (rset1.next())
+			ps1.setInt(1, 1);
+			try (ResultSet rs1 = ps1.executeQuery();
+				PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist Where key_npc_id = ? and spawntype = ? ORDER BY id"))
 			{
-				int keyNpcId = rset1.getInt("key_npc_id");
-				
-				statement2.setInt(1, keyNpcId);
-				statement2.setInt(2, 1);
-				ResultSet rset2 = statement2.executeQuery();
-				statement2.clearParameters();
-				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
-				
-				_physicalSpawns = new FastList<>();
-				
-				while (rset2.next())
+				while (rs1.next())
 				{
-					template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
-					if (template1 != null)
-					{
-						spawnDat = new L2Spawn(template1);
-						spawnDat.setAmount(rset2.getInt("count"));
-						spawnDat.setLocx(rset2.getInt("locx"));
-						spawnDat.setLocy(rset2.getInt("locy"));
-						spawnDat.setLocz(rset2.getInt("locz"));
-						spawnDat.setHeading(rset2.getInt("heading"));
-						spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
-						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-						_physicalSpawns.add(spawnDat);
-						loaded++;
-					}
-					else
+					int keyNpcId = rs1.getInt("key_npc_id");
+					
+					ps2.setInt(1, keyNpcId);
+					ps2.setInt(2, 1);
+					try (ResultSet rs2 = ps2.executeQuery())
 					{
-						_log.warning("FourSepulchersManager.LoadPhysicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+						_physicalSpawns = new FastList<>();
+						while (rs2.next())
+						{
+							template1 = NpcTable.getInstance().getTemplate(rs2.getInt("npc_templateid"));
+							if (template1 != null)
+							{
+								spawnDat = new L2Spawn(template1);
+								spawnDat.setAmount(rs2.getInt("count"));
+								spawnDat.setLocx(rs2.getInt("locx"));
+								spawnDat.setLocy(rs2.getInt("locy"));
+								spawnDat.setLocz(rs2.getInt("locz"));
+								spawnDat.setHeading(rs2.getInt("heading"));
+								spawnDat.setRespawnDelay(rs2.getInt("respawn_delay"));
+								SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+								_physicalSpawns.add(spawnDat);
+								loaded++;
+							}
+							else
+							{
+								_log.warning("FourSepulchersManager.LoadPhysicalMonsters: Data missing in NPC table for ID: " + rs2.getInt("npc_templateid") + ".");
+							}
+						}
 					}
+					ps2.clearParameters();
+					_physicalMonsters.put(keyNpcId, _physicalSpawns);
 				}
-				
-				rset2.close();
-				_physicalMonsters.put(keyNpcId, _physicalSpawns);
 			}
-			
-			rset1.close();
-			statement1.close();
-			statement2.close();
-			
 			_log.info(getClass().getSimpleName() + ": loaded " + loaded + " Physical type monsters spawns.");
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "FourSepulchersManager.LoadPhysicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}
 	
 	private void loadMagicalMonsters()
 	{
-		
 		_magicalMonsters.clear();
 		
 		int loaded = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
 		{
-			PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
-			statement1.setInt(1, 2);
-			ResultSet rset1 = statement1.executeQuery();
-			
-			PreparedStatement statement2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id");
-			while (rset1.next())
+			ps1.setInt(1, 2);
+			try (ResultSet rs1 = ps1.executeQuery();
+				PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id"))
 			{
-				int keyNpcId = rset1.getInt("key_npc_id");
-				
-				statement2.setInt(1, keyNpcId);
-				statement2.setInt(2, 2);
-				ResultSet rset2 = statement2.executeQuery();
-				statement2.clearParameters();
-				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
-				
-				_magicalSpawns = new FastList<>();
-				
-				while (rset2.next())
+				while (rs1.next())
 				{
-					template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
-					if (template1 != null)
-					{
-						spawnDat = new L2Spawn(template1);
-						spawnDat.setAmount(rset2.getInt("count"));
-						spawnDat.setLocx(rset2.getInt("locx"));
-						spawnDat.setLocy(rset2.getInt("locy"));
-						spawnDat.setLocz(rset2.getInt("locz"));
-						spawnDat.setHeading(rset2.getInt("heading"));
-						spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
-						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-						_magicalSpawns.add(spawnDat);
-						loaded++;
-					}
-					else
+					int keyNpcId = rs1.getInt("key_npc_id");
+					
+					ps2.setInt(1, keyNpcId);
+					ps2.setInt(2, 2);
+					try (ResultSet rset2 = ps2.executeQuery())
 					{
-						_log.warning("FourSepulchersManager.LoadMagicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+						_magicalSpawns = new FastList<>();
+						
+						while (rset2.next())
+						{
+							template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
+							if (template1 != null)
+							{
+								spawnDat = new L2Spawn(template1);
+								spawnDat.setAmount(rset2.getInt("count"));
+								spawnDat.setLocx(rset2.getInt("locx"));
+								spawnDat.setLocy(rset2.getInt("locy"));
+								spawnDat.setLocz(rset2.getInt("locz"));
+								spawnDat.setHeading(rset2.getInt("heading"));
+								spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
+								SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+								_magicalSpawns.add(spawnDat);
+								loaded++;
+							}
+							else
+							{
+								_log.warning("FourSepulchersManager.LoadMagicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+							}
+						}
 					}
+					ps2.clearParameters();
+					_magicalMonsters.put(keyNpcId, _magicalSpawns);
 				}
-				
-				rset2.close();
-				_magicalMonsters.put(keyNpcId, _magicalSpawns);
 			}
-			
-			rset1.close();
-			statement1.close();
-			statement2.close();
-			
 			_log.info(getClass().getSimpleName() + ": loaded " + loaded + " Magical type monsters spawns.");
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "FourSepulchersManager.LoadMagicalMonsters: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}
@@ -638,129 +620,116 @@ public class FourSepulchersManager
 		_archonSpawned.clear();
 		
 		int loaded = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
 		{
-			PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
-			statement1.setInt(1, 5);
-			ResultSet rset1 = statement1.executeQuery();
-			
-			PreparedStatement statement2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id");
-			while (rset1.next())
+			ps1.setInt(1, 5);
+			try (ResultSet rs1 = ps1.executeQuery();
+				PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? AND spawntype = ? ORDER BY id"))
 			{
-				int keyNpcId = rset1.getInt("key_npc_id");
-				
-				statement2.setInt(1, keyNpcId);
-				statement2.setInt(2, 5);
-				ResultSet rset2 = statement2.executeQuery();
-				statement2.clearParameters();
-				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
-				
-				_dukeFinalSpawns = new FastList<>();
-				
-				while (rset2.next())
+				while (rs1.next())
 				{
-					template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
-					if (template1 != null)
-					{
-						spawnDat = new L2Spawn(template1);
-						spawnDat.setAmount(rset2.getInt("count"));
-						spawnDat.setLocx(rset2.getInt("locx"));
-						spawnDat.setLocy(rset2.getInt("locy"));
-						spawnDat.setLocz(rset2.getInt("locz"));
-						spawnDat.setHeading(rset2.getInt("heading"));
-						spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
-						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-						_dukeFinalSpawns.add(spawnDat);
-						loaded++;
-					}
-					else
+					int keyNpcId = rs1.getInt("key_npc_id");
+					
+					ps2.setInt(1, keyNpcId);
+					ps2.setInt(2, 5);
+					try (ResultSet rset2 = ps2.executeQuery())
 					{
-						_log.warning("FourSepulchersManager.LoadDukeMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+						ps2.clearParameters();
+						
+						_dukeFinalSpawns = new FastList<>();
+						
+						while (rset2.next())
+						{
+							template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
+							if (template1 != null)
+							{
+								spawnDat = new L2Spawn(template1);
+								spawnDat.setAmount(rset2.getInt("count"));
+								spawnDat.setLocx(rset2.getInt("locx"));
+								spawnDat.setLocy(rset2.getInt("locy"));
+								spawnDat.setLocz(rset2.getInt("locz"));
+								spawnDat.setHeading(rset2.getInt("heading"));
+								spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
+								SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+								_dukeFinalSpawns.add(spawnDat);
+								loaded++;
+							}
+							else
+							{
+								_log.warning("FourSepulchersManager.LoadDukeMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+							}
+						}
 					}
+					ps2.clearParameters();
+					_dukeFinalMobs.put(keyNpcId, _dukeFinalSpawns);
+					_archonSpawned.put(keyNpcId, false);
 				}
-				
-				rset2.close();
-				_dukeFinalMobs.put(keyNpcId, _dukeFinalSpawns);
-				_archonSpawned.put(keyNpcId, false);
 			}
-			
-			rset1.close();
-			statement1.close();
-			statement2.close();
-			
 			_log.info(getClass().getSimpleName() + ": loaded " + loaded + " Church of duke monsters spawns.");
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "FourSepulchersManager.LoadDukeMonsters: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}
 	
 	private void loadEmperorsGraveMonsters()
 	{
-		
 		_emperorsGraveNpcs.clear();
 		
 		int loaded = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id"))
 		{
-			PreparedStatement statement1 = con.prepareStatement("SELECT Distinct key_npc_id FROM four_sepulchers_spawnlist Where spawntype = ? ORDER BY key_npc_id");
-			statement1.setInt(1, 6);
-			ResultSet rset1 = statement1.executeQuery();
-			
-			PreparedStatement statement2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? and spawntype = ? ORDER BY id");
-			while (rset1.next())
+			ps1.setInt(1, 6);
+			try (ResultSet rs1 = ps1.executeQuery();
+				PreparedStatement ps2 = con.prepareStatement("SELECT id, count, npc_templateid, locx, locy, locz, heading, respawn_delay, key_npc_id FROM four_sepulchers_spawnlist WHERE key_npc_id = ? and spawntype = ? ORDER BY id"))
 			{
-				int keyNpcId = rset1.getInt("key_npc_id");
-				
-				statement2.setInt(1, keyNpcId);
-				statement2.setInt(2, 6);
-				ResultSet rset2 = statement2.executeQuery();
-				statement2.clearParameters();
-				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
-				
-				_emperorsGraveSpawns = new FastList<>();
-				
-				while (rset2.next())
+				while (rs1.next())
 				{
-					template1 = NpcTable.getInstance().getTemplate(rset2.getInt("npc_templateid"));
-					if (template1 != null)
-					{
-						spawnDat = new L2Spawn(template1);
-						spawnDat.setAmount(rset2.getInt("count"));
-						spawnDat.setLocx(rset2.getInt("locx"));
-						spawnDat.setLocy(rset2.getInt("locy"));
-						spawnDat.setLocz(rset2.getInt("locz"));
-						spawnDat.setHeading(rset2.getInt("heading"));
-						spawnDat.setRespawnDelay(rset2.getInt("respawn_delay"));
-						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-						_emperorsGraveSpawns.add(spawnDat);
-						loaded++;
-					}
-					else
+					int keyNpcId = rs1.getInt("key_npc_id");
+					
+					ps2.setInt(1, keyNpcId);
+					ps2.setInt(2, 6);
+					try (ResultSet rs2 = ps2.executeQuery())
 					{
-						_log.warning("FourSepulchersManager.LoadEmperorsGraveMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
+						_emperorsGraveSpawns = new FastList<>();
+						
+						while (rs2.next())
+						{
+							template1 = NpcTable.getInstance().getTemplate(rs2.getInt("npc_templateid"));
+							if (template1 != null)
+							{
+								spawnDat = new L2Spawn(template1);
+								spawnDat.setAmount(rs2.getInt("count"));
+								spawnDat.setLocx(rs2.getInt("locx"));
+								spawnDat.setLocy(rs2.getInt("locy"));
+								spawnDat.setLocz(rs2.getInt("locz"));
+								spawnDat.setHeading(rs2.getInt("heading"));
+								spawnDat.setRespawnDelay(rs2.getInt("respawn_delay"));
+								SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+								_emperorsGraveSpawns.add(spawnDat);
+								loaded++;
+							}
+							else
+							{
+								_log.warning("FourSepulchersManager.LoadEmperorsGraveMonsters: Data missing in NPC table for ID: " + rs2.getInt("npc_templateid") + ".");
+							}
+						}
 					}
+					ps2.clearParameters();
+					_emperorsGraveNpcs.put(keyNpcId, _emperorsGraveSpawns);
 				}
-				
-				rset2.close();
-				_emperorsGraveNpcs.put(keyNpcId, _emperorsGraveSpawns);
 			}
-			
-			rset1.close();
-			statement1.close();
-			statement2.close();
-			
 			_log.info(getClass().getSimpleName() + ": loaded " + loaded + " Emperor's grave NPC spawns.");
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "FourSepulchersManager.LoadEmperorsGraveMonsters: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}

+ 35 - 44
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/GrandBossManager.java

@@ -18,6 +18,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Date;
 import java.util.Map;
 import java.util.logging.Level;
@@ -72,28 +73,28 @@ public class GrandBossManager
 		_bosses = new FastMap<>();
 		_storedInfo = new TIntObjectHashMap<>();
 		_bossStatus = new TIntIntHashMap();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * from grandboss_data ORDER BY boss_id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * from grandboss_data ORDER BY boss_id");
-			ResultSet rset = statement.executeQuery();
-			while (rset.next())
+			while (rs.next())
 			{
 				// Read all info from DB, and store it for AI to read and decide what to do
 				// faster than accessing DB in real time
 				StatsSet info = new StatsSet();
-				int bossId = rset.getInt("boss_id");
-				info.set("loc_x", rset.getInt("loc_x"));
-				info.set("loc_y", rset.getInt("loc_y"));
-				info.set("loc_z", rset.getInt("loc_z"));
-				info.set("heading", rset.getInt("heading"));
-				info.set("respawn_time", rset.getLong("respawn_time"));
-				double HP = rset.getDouble("currentHP"); // jython doesn't recognize doubles
+				int bossId = rs.getInt("boss_id");
+				info.set("loc_x", rs.getInt("loc_x"));
+				info.set("loc_y", rs.getInt("loc_y"));
+				info.set("loc_z", rs.getInt("loc_z"));
+				info.set("heading", rs.getInt("heading"));
+				info.set("respawn_time", rs.getLong("respawn_time"));
+				double HP = rs.getDouble("currentHP"); // jython doesn't recognize doubles
 				int true_HP = (int) HP; // so use java's ability to type cast
 				info.set("currentHP", true_HP); // to convert double to int
-				double MP = rset.getDouble("currentMP");
+				double MP = rs.getDouble("currentMP");
 				int true_MP = (int) MP;
 				info.set("currentMP", true_MP);
-				int status = rset.getInt("status");
+				int status = rs.getInt("status");
 				_bossStatus.put(bossId, status);
 				_storedInfo.put(bossId, info);
 				_log.info(getClass().getSimpleName() + ": " + NpcTable.getInstance().getTemplate(bossId).getName() + "(" + bossId + ") status is " + status + ".");
@@ -101,13 +102,8 @@ public class GrandBossManager
 				{
 					_log.info(getClass().getSimpleName() + ": Next spawn date of " + NpcTable.getInstance().getTemplate(bossId).getName() + " is " + new Date(info.getLong("respawn_time")) + ".");
 				}
-				
-				info = null;
 			}
 			_log.info(getClass().getSimpleName() + ": Loaded " + _storedInfo.size() + " Instances");
-			
-			rset.close();
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -141,21 +137,16 @@ public class GrandBossManager
 			zones.put(zone.getId(), new L2FastList<Integer>());
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * from grandboss_list ORDER BY player_id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * from grandboss_list ORDER BY player_id");
-			ResultSet rset = statement.executeQuery();
-			
-			while (rset.next())
+			while (rs.next())
 			{
-				int id = rset.getInt("player_id");
-				int zone_id = rset.getInt("zone");
+				int id = rs.getInt("player_id");
+				int zone_id = rs.getInt("zone");
 				zones.get(zone_id).add(id);
 			}
-			
-			rset.close();
-			statement.close();
-			
 			_log.info(getClass().getSimpleName() + ": Initialized " + _zones.size() + " Grand Boss Zones");
 		}
 		catch (SQLException e)
@@ -373,22 +364,22 @@ public class GrandBossManager
 			
 			if (statusOnly || (boss == null) || (info == null))
 			{
-				try (PreparedStatement statement = con.prepareStatement(UPDATE_GRAND_BOSS_DATA2))
+				try (PreparedStatement ps = con.prepareStatement(UPDATE_GRAND_BOSS_DATA2))
 				{
-					statement.setInt(1, _bossStatus.get(bossId));
-					statement.setInt(2, bossId);
-					statement.executeUpdate();
+					ps.setInt(1, _bossStatus.get(bossId));
+					ps.setInt(2, bossId);
+					ps.executeUpdate();
 				}
 			}
 			else
 			{
-				try (PreparedStatement statement = con.prepareStatement(UPDATE_GRAND_BOSS_DATA))
+				try (PreparedStatement ps = con.prepareStatement(UPDATE_GRAND_BOSS_DATA))
 				{
-					statement.setInt(1, boss.getX());
-					statement.setInt(2, boss.getY());
-					statement.setInt(3, boss.getZ());
-					statement.setInt(4, boss.getHeading());
-					statement.setLong(5, info.getLong("respawn_time"));
+					ps.setInt(1, boss.getX());
+					ps.setInt(2, boss.getY());
+					ps.setInt(3, boss.getZ());
+					ps.setInt(4, boss.getHeading());
+					ps.setLong(5, info.getLong("respawn_time"));
 					double hp = boss.getCurrentHp();
 					double mp = boss.getCurrentMp();
 					if (boss.isDead())
@@ -396,11 +387,11 @@ public class GrandBossManager
 						hp = boss.getMaxHp();
 						mp = boss.getMaxMp();
 					}
-					statement.setDouble(6, hp);
-					statement.setDouble(7, mp);
-					statement.setInt(8, _bossStatus.get(bossId));
-					statement.setInt(9, bossId);
-					statement.executeUpdate();
+					ps.setDouble(6, hp);
+					ps.setDouble(7, mp);
+					ps.setInt(8, _bossStatus.get(bossId));
+					ps.setInt(9, bossId);
+					ps.executeUpdate();
 				}
 			}
 		}

+ 19 - 20
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/HellboundManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ScheduledFuture;
@@ -254,35 +254,34 @@ public class HellboundManager
 	
 	private final void loadSpawns()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery(LOAD_SPAWNS))
 		{
-			final PreparedStatement statement = con.prepareStatement(LOAD_SPAWNS);
-			final ResultSet rset = statement.executeQuery();
-			
 			HellboundSpawn spawnDat;
 			L2NpcTemplate template;
-			while (rset.next())
+			while (rs.next())
 			{
-				template = NpcTable.getInstance().getTemplate(rset.getInt("npc_templateid"));
+				template = NpcTable.getInstance().getTemplate(rs.getInt("npc_templateid"));
 				if (template != null)
 				{
 					spawnDat = new HellboundSpawn(template);
 					spawnDat.setAmount(1);
-					spawnDat.setLocx(rset.getInt("locx"));
-					spawnDat.setLocy(rset.getInt("locy"));
-					spawnDat.setLocz(rset.getInt("locz"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
+					spawnDat.setLocx(rs.getInt("locx"));
+					spawnDat.setLocy(rs.getInt("locy"));
+					spawnDat.setLocz(rs.getInt("locz"));
+					spawnDat.setHeading(rs.getInt("heading"));
+					spawnDat.setRespawnDelay(rs.getInt("respawn_delay"));
 					spawnDat.setRespawnMinDelay(0);
 					spawnDat.setRespawnMaxDelay(0);
-					int respawnRandom = (rset.getInt("respawn_random"));
+					int respawnRandom = (rs.getInt("respawn_random"));
 					if (respawnRandom > 0) // Random respawn time, if needed
 					{
-						spawnDat.setRespawnMinDelay(Math.max(rset.getInt("respawn_delay") - respawnRandom, 1));
-						spawnDat.setRespawnMaxDelay(rset.getInt("respawn_delay") + respawnRandom);
+						spawnDat.setRespawnMinDelay(Math.max(rs.getInt("respawn_delay") - respawnRandom, 1));
+						spawnDat.setRespawnMaxDelay(rs.getInt("respawn_delay") + respawnRandom);
 					}
-					spawnDat.setMinLvl(rset.getInt("min_hellbound_level"));
-					spawnDat.setMaxLvl(rset.getInt("max_hellbound_level"));
+					spawnDat.setMinLvl(rs.getInt("min_hellbound_level"));
+					spawnDat.setMaxLvl(rs.getInt("max_hellbound_level"));
 					
 					// _population.put(spawnDat, null);
 					_population.add(spawnDat);
@@ -290,11 +289,11 @@ public class HellboundManager
 				}
 				else
 				{
-					_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rset.getInt("npc_templateid") + ".");
+					_log.warning(getClass().getSimpleName() + ": Data missing in NPC table for ID: " + rs.getInt("npc_templateid") + ".");
 				}
 			}
-			rset.close();
-			statement.close();
+			rs.close();
+			s.close();
 		}
 		catch (Exception e)
 		{

+ 27 - 31
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/InstanceManager.java

@@ -110,15 +110,14 @@ public class InstanceManager extends DocumentParser
 			restoreInstanceTimes(playerObjId);
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(ADD_INSTANCE_TIME))
 		{
-			PreparedStatement statement = con.prepareStatement(ADD_INSTANCE_TIME);
-			statement.setInt(1, playerObjId);
-			statement.setInt(2, id);
-			statement.setLong(3, time);
-			statement.setLong(4, time);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, playerObjId);
+			ps.setInt(2, id);
+			ps.setLong(3, time);
+			ps.setLong(4, time);
+			ps.execute();
 			_playerInstanceTimes.get(playerObjId).put(id, time);
 		}
 		catch (Exception e)
@@ -133,13 +132,12 @@ public class InstanceManager extends DocumentParser
 	 */
 	public void deleteInstanceTime(int playerObjId, int id)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(DELETE_INSTANCE_TIME))
 		{
-			PreparedStatement statement = con.prepareStatement(DELETE_INSTANCE_TIME);
-			statement.setInt(1, playerObjId);
-			statement.setInt(2, id);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, playerObjId);
+			ps.setInt(2, id);
+			ps.execute();
 			_playerInstanceTimes.get(playerObjId).remove(id);
 		}
 		catch (Exception e)
@@ -158,28 +156,26 @@ public class InstanceManager extends DocumentParser
 			return; // already restored
 		}
 		_playerInstanceTimes.put(playerObjId, new FastMap<Integer, Long>());
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(RESTORE_INSTANCE_TIMES))
 		{
-			PreparedStatement statement = con.prepareStatement(RESTORE_INSTANCE_TIMES);
-			statement.setInt(1, playerObjId);
-			ResultSet rset = statement.executeQuery();
-			
-			while (rset.next())
+			ps.setInt(1, playerObjId);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				int id = rset.getInt("instanceId");
-				long time = rset.getLong("time");
-				if (time < System.currentTimeMillis())
+				while (rs.next())
 				{
-					deleteInstanceTime(playerObjId, id);
-				}
-				else
-				{
-					_playerInstanceTimes.get(playerObjId).put(id, time);
+					int id = rs.getInt("instanceId");
+					long time = rs.getLong("time");
+					if (time < System.currentTimeMillis())
+					{
+						deleteInstanceTime(playerObjId, id);
+					}
+					else
+					{
+						_playerInstanceTimes.get(playerObjId).put(id, time);
+					}
 				}
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 57 - 62
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/ItemsOnGroundManager.java

@@ -18,6 +18,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -33,8 +34,7 @@ import com.l2jserver.util.L2FastList;
 
 /**
  * This class manage all items on ground.
- * @author DiezelMax, original idea.
- * @author Enforcer, actual build.
+ * @author Enforcer
  */
 public class ItemsOnGroundManager implements Runnable
 {
@@ -67,23 +67,23 @@ public class ItemsOnGroundManager implements Runnable
 		// if DestroyPlayerDroppedItem was previously false, items currently protected will be added to ItemsAutoDestroy
 		if (Config.DESTROY_DROPPED_PLAYER_ITEM)
 		{
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			String str = null;
+			if (!Config.DESTROY_EQUIPABLE_PLAYER_ITEM)
 			{
-				String str = null;
-				if (!Config.DESTROY_EQUIPABLE_PLAYER_ITEM)
-				{
-					// Recycle misc. items only
-					str = "update itemsonground set drop_time=? where drop_time=-1 and equipable=0";
-				}
-				else if (Config.DESTROY_EQUIPABLE_PLAYER_ITEM)
-				{
-					// Recycle all items including equip-able
-					str = "update itemsonground set drop_time=? where drop_time=-1";
-				}
-				PreparedStatement statement = con.prepareStatement(str);
-				statement.setLong(1, System.currentTimeMillis());
-				statement.execute();
-				statement.close();
+				// Recycle misc. items only
+				str = "UPDATE itemsonground SET drop_time = ? WHERE drop_time = -1 AND equipable = 0";
+			}
+			else if (Config.DESTROY_EQUIPABLE_PLAYER_ITEM)
+			{
+				// Recycle all items including equip-able
+				str = "UPDATE itemsonground SET drop_time = ? WHERE drop_time = -1";
+			}
+			
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement ps = con.prepareStatement(str))
+			{
+				ps.setLong(1, System.currentTimeMillis());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -92,52 +92,50 @@ public class ItemsOnGroundManager implements Runnable
 		}
 		
 		// Add items to world
-		L2ItemInstance item;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable FROM itemsonground"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable FROM itemsonground");
-			ResultSet rset;
 			int count = 0;
-			rset = statement.executeQuery();
-			while (rset.next())
+			try (ResultSet rs = ps.executeQuery())
 			{
-				item = new L2ItemInstance(rset.getInt(1), rset.getInt(2));
-				L2World.getInstance().storeObject(item);
-				// this check and..
-				if (item.isStackable() && (rset.getInt(3) > 1))
+				L2ItemInstance item;
+				while (rs.next())
 				{
-					item.setCount(rset.getInt(3));
-				}
-				// this, are really necessary?
-				if (rset.getInt(4) > 0)
-				{
-					item.setEnchantLevel(rset.getInt(4));
-				}
-				item.getPosition().setWorldPosition(rset.getInt(5), rset.getInt(6), rset.getInt(7));
-				item.getPosition().setWorldRegion(L2World.getInstance().getRegion(item.getPosition().getWorldPosition()));
-				item.getPosition().getWorldRegion().addVisibleObject(item);
-				final long dropTime = rset.getLong(8);
-				item.setDropTime(dropTime);
-				item.setProtected(dropTime == -1);
-				item.setIsVisible(true);
-				L2World.getInstance().addVisibleObject(item, item.getPosition().getWorldRegion());
-				_items.add(item);
-				count++;
-				// add to ItemsAutoDestroy only items not protected
-				if (!Config.LIST_PROTECTED_ITEMS.contains(item.getItemId()))
-				{
-					if (dropTime > -1)
+					item = new L2ItemInstance(rs.getInt(1), rs.getInt(2));
+					L2World.getInstance().storeObject(item);
+					// this check and..
+					if (item.isStackable() && (rs.getInt(3) > 1))
+					{
+						item.setCount(rs.getInt(3));
+					}
+					// this, are really necessary?
+					if (rs.getInt(4) > 0)
 					{
-						if (((Config.AUTODESTROY_ITEM_AFTER > 0) && (item.getItemType() != L2EtcItemType.HERB)) || ((Config.HERB_AUTO_DESTROY_TIME > 0) && (item.getItemType() == L2EtcItemType.HERB)))
+						item.setEnchantLevel(rs.getInt(4));
+					}
+					item.getPosition().setWorldPosition(rs.getInt(5), rs.getInt(6), rs.getInt(7));
+					item.getPosition().setWorldRegion(L2World.getInstance().getRegion(item.getPosition().getWorldPosition()));
+					item.getPosition().getWorldRegion().addVisibleObject(item);
+					final long dropTime = rs.getLong(8);
+					item.setDropTime(dropTime);
+					item.setProtected(dropTime == -1);
+					item.setIsVisible(true);
+					L2World.getInstance().addVisibleObject(item, item.getPosition().getWorldRegion());
+					_items.add(item);
+					count++;
+					// add to ItemsAutoDestroy only items not protected
+					if (!Config.LIST_PROTECTED_ITEMS.contains(item.getItemId()))
+					{
+						if (dropTime > -1)
 						{
-							ItemsAutoDestroy.getInstance().addItem(item);
+							if (((Config.AUTODESTROY_ITEM_AFTER > 0) && (item.getItemType() != L2EtcItemType.HERB)) || ((Config.HERB_AUTO_DESTROY_TIME > 0) && (item.getItemType() == L2EtcItemType.HERB)))
+							{
+								ItemsAutoDestroy.getInstance().addItem(item);
+							}
 						}
 					}
 				}
 			}
-			rset.close();
-			statement.close();
-			
 			_log.info(getClass().getSimpleName() + ": Loaded " + count + " items.");
 		}
 		catch (Exception e)
@@ -180,11 +178,10 @@ public class ItemsOnGroundManager implements Runnable
 	
 	public void emptyTable()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement())
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM itemsonground");
-			statement.execute();
-			statement.close();
+			s.executeQuery("DELETE FROM itemsonground");
 		}
 		catch (Exception e1)
 		{
@@ -207,10 +204,9 @@ public class ItemsOnGroundManager implements Runnable
 			return;
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("INSERT INTO itemsonground(object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable) VALUES(?,?,?,?,?,?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO itemsonground(object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable) VALUES(?,?,?,?,?,?,?,?,?)");
-			
 			for (L2ItemInstance item : _items)
 			{
 				if (item == null)
@@ -242,7 +238,6 @@ public class ItemsOnGroundManager implements Runnable
 					_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error while inserting into table ItemsOnGround: " + e.getMessage(), e);
 				}
 			}
-			statement.close();
 		}
 		catch (SQLException e)
 		{

+ 25 - 28
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MailManager.java

@@ -18,6 +18,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -54,14 +55,14 @@ public class MailManager
 	private void load()
 	{
 		int count = 0;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement ps = con.createStatement();
+			ResultSet rs = ps.executeQuery("SELECT * FROM messages ORDER BY expiration"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM messages ORDER BY expiration");
-			ResultSet rset1 = statement.executeQuery();
-			while (rset1.next())
+			while (rs.next())
 			{
 				
-				Message msg = new Message(rset1);
+				Message msg = new Message(rs);
 				
 				int msgId = msg.getId();
 				_messages.put(msgId, msg);
@@ -79,8 +80,6 @@ public class MailManager
 					ThreadPoolManager.getInstance().scheduleGeneral(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
 				}
 			}
-			rset1.close();
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -167,11 +166,10 @@ public class MailManager
 	public void sendMessage(Message msg)
 	{
 		_messages.put(msg.getId(), msg);
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = Message.getStatement(msg, con))
 		{
-			PreparedStatement stmt = Message.getStatement(msg, con);
-			stmt.execute();
-			stmt.close();
+			ps.execute();
 		}
 		catch (SQLException e)
 		{
@@ -244,12 +242,11 @@ public class MailManager
 	
 	public final void markAsReadInDb(int msgId)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE messages SET isUnread = 'false' WHERE messageId = ?"))
 		{
-			PreparedStatement stmt = con.prepareStatement("UPDATE messages SET isUnread = 'false' WHERE messageId = ?");
-			stmt.setInt(1, msgId);
-			stmt.execute();
-			stmt.close();
+			ps.setInt(1, msgId);
+			ps.execute();
 		}
 		catch (SQLException e)
 		{
@@ -260,10 +257,10 @@ public class MailManager
 	public final void markAsDeletedBySenderInDb(int msgId)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement stmt = con.prepareStatement("UPDATE messages SET isDeletedBySender = 'true' WHERE messageId = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE messages SET isDeletedBySender = 'true' WHERE messageId = ?"))
 		{
-			stmt.setInt(1, msgId);
-			stmt.execute();
+			ps.setInt(1, msgId);
+			ps.execute();
 		}
 		catch (SQLException e)
 		{
@@ -274,10 +271,10 @@ public class MailManager
 	public final void markAsDeletedByReceiverInDb(int msgId)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement stmt = con.prepareStatement("UPDATE messages SET isDeletedByReceiver = 'true' WHERE messageId = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE messages SET isDeletedByReceiver = 'true' WHERE messageId = ?"))
 		{
-			stmt.setInt(1, msgId);
-			stmt.execute();
+			ps.setInt(1, msgId);
+			ps.execute();
 		}
 		catch (SQLException e)
 		{
@@ -288,10 +285,10 @@ public class MailManager
 	public final void removeAttachmentsInDb(int msgId)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement stmt = con.prepareStatement("UPDATE messages SET hasAttachments = 'false' WHERE messageId = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE messages SET hasAttachments = 'false' WHERE messageId = ?"))
 		{
-			stmt.setInt(1, msgId);
-			stmt.execute();
+			ps.setInt(1, msgId);
+			ps.execute();
 		}
 		catch (SQLException e)
 		{
@@ -302,10 +299,10 @@ public class MailManager
 	public final void deleteMessageInDb(int msgId)
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement stmt = con.prepareStatement("DELETE FROM messages WHERE messageId = ?"))
+			PreparedStatement ps = con.prepareStatement("DELETE FROM messages WHERE messageId = ?"))
 		{
-			stmt.setInt(1, msgId);
-			stmt.execute();
+			ps.setInt(1, msgId);
+			ps.execute();
 		}
 		catch (SQLException e)
 		{

+ 5 - 6
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/MercTicketManager.java

@@ -15,8 +15,8 @@
 package com.l2jserver.gameserver.instancemanager;
 
 import java.sql.Connection;
-import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
@@ -146,11 +146,10 @@ public class MercTicketManager
 	 */
 	private final void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM castle_siege_guards Where isHired = 1"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM castle_siege_guards Where isHired = 1");
-			ResultSet rs = statement.executeQuery();
-			
 			int npcId;
 			int itemId;
 			int x, y, z;
@@ -200,7 +199,7 @@ public class MercTicketManager
 				}
 			}
 			rs.close();
-			statement.close();
+			s.close();
 			
 			_log.info(getClass().getSimpleName() + ": Loaded: " + _droppedTickets.size() + " Mercenary Tickets");
 		}

+ 16 - 19
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/RaidBossPointsManager.java

@@ -18,6 +18,7 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -58,15 +59,15 @@ public class RaidBossPointsManager
 	private final void init()
 	{
 		_list = new FastMap<>();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT `charId`,`boss_id`,`points` FROM `character_raid_points`"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT `charId`,`boss_id`,`points` FROM `character_raid_points`");
-			ResultSet rset = statement.executeQuery();
-			while (rset.next())
+			while (rs.next())
 			{
-				int charId = rset.getInt("charId");
-				int bossId = rset.getInt("boss_id");
-				int points = rset.getInt("points");
+				int charId = rs.getInt("charId");
+				int bossId = rs.getInt("boss_id");
+				int points = rs.getInt("points");
 				Map<Integer, Integer> values = _list.get(charId);
 				if (values == null)
 				{
@@ -75,8 +76,6 @@ public class RaidBossPointsManager
 				values.put(bossId, points);
 				_list.put(charId, values);
 			}
-			rset.close();
-			statement.close();
 			_log.info(getClass().getSimpleName() + ": Loaded " + _list.size() + " Characters Raid Points.");
 		}
 		catch (SQLException e)
@@ -87,14 +86,13 @@ public class RaidBossPointsManager
 	
 	public final void updatePointsInDB(L2PcInstance player, int raidId, int points)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("REPLACE INTO character_raid_points (`charId`,`boss_id`,`points`) VALUES (?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("REPLACE INTO character_raid_points (`charId`,`boss_id`,`points`) VALUES (?,?,?)");
-			statement.setInt(1, player.getObjectId());
-			statement.setInt(2, raidId);
-			statement.setInt(3, points);
-			statement.executeUpdate();
-			statement.close();
+			ps.setInt(1, player.getObjectId());
+			ps.setInt(2, raidId);
+			ps.setInt(3, points);
+			ps.executeUpdate();
 		}
 		catch (Exception e)
 		{
@@ -147,11 +145,10 @@ public class RaidBossPointsManager
 	
 	public final void cleanUp()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("DELETE from character_raid_points WHERE charId > 0"))
 		{
-			final PreparedStatement statement = con.prepareStatement("DELETE from character_raid_points WHERE charId > 0");
 			statement.executeUpdate();
-			statement.close();
 			_list.clear();
 		}
 		catch (Exception e)

+ 40 - 45
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/SiegeGuardManager.java

@@ -105,15 +105,14 @@ public class SiegeGuardManager
 	 */
 	public void removeMerc(int npcId, int x, int y, int z)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("Delete From castle_siege_guards Where npcId = ? And x = ? AND y = ? AND z = ? AND isHired = 1"))
 		{
-			PreparedStatement statement = con.prepareStatement("Delete From castle_siege_guards Where npcId = ? And x = ? AND y = ? AND z = ? AND isHired = 1");
-			statement.setInt(1, npcId);
-			statement.setInt(2, x);
-			statement.setInt(3, y);
-			statement.setInt(4, z);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, npcId);
+			ps.setInt(2, x);
+			ps.setInt(3, y);
+			ps.setInt(4, z);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -126,12 +125,11 @@ public class SiegeGuardManager
 	 */
 	public void removeMercs()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("Delete From castle_siege_guards Where castleId = ? And isHired = 1"))
 		{
-			PreparedStatement statement = con.prepareStatement("Delete From castle_siege_guards Where castleId = ? And isHired = 1");
-			statement.setInt(1, getCastle().getCastleId());
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getCastle().getCastleId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -195,46 +193,44 @@ public class SiegeGuardManager
 	 */
 	private void loadSiegeGuard()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM castle_siege_guards Where castleId = ? And isHired = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM castle_siege_guards Where castleId = ? And isHired = ?");
-			statement.setInt(1, getCastle().getCastleId());
+			ps.setInt(1, getCastle().getCastleId());
 			if (getCastle().getOwnerId() > 0)
 			{
-				statement.setInt(2, 1);
+				ps.setInt(2, 1);
 			}
 			else
 			{
-				statement.setInt(2, 0);
+				ps.setInt(2, 0);
 			}
-			ResultSet rs = statement.executeQuery();
-			
-			L2Spawn spawn1;
-			L2NpcTemplate template1;
-			
-			while (rs.next())
+			try (ResultSet rs = ps.executeQuery())
 			{
-				template1 = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
-				if (template1 != null)
+				L2Spawn spawn1;
+				L2NpcTemplate template1;
+				while (rs.next())
 				{
-					spawn1 = new L2Spawn(template1);
-					spawn1.setAmount(1);
-					spawn1.setLocx(rs.getInt("x"));
-					spawn1.setLocy(rs.getInt("y"));
-					spawn1.setLocz(rs.getInt("z"));
-					spawn1.setHeading(rs.getInt("heading"));
-					spawn1.setRespawnDelay(rs.getInt("respawnDelay"));
-					spawn1.setLocation(0);
-					
-					_siegeGuardSpawn.add(spawn1);
-				}
-				else
-				{
-					_log.warning(getClass().getSimpleName() + ": Missing npc data in npc table for id: " + rs.getInt("npcId"));
+					template1 = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
+					if (template1 != null)
+					{
+						spawn1 = new L2Spawn(template1);
+						spawn1.setAmount(1);
+						spawn1.setLocx(rs.getInt("x"));
+						spawn1.setLocy(rs.getInt("y"));
+						spawn1.setLocz(rs.getInt("z"));
+						spawn1.setHeading(rs.getInt("heading"));
+						spawn1.setRespawnDelay(rs.getInt("respawnDelay"));
+						spawn1.setLocation(0);
+						
+						_siegeGuardSpawn.add(spawn1);
+					}
+					else
+					{
+						_log.warning(getClass().getSimpleName() + ": Missing npc data in npc table for id: " + rs.getInt("npcId"));
+					}
 				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -253,9 +249,9 @@ public class SiegeGuardManager
 	 */
 	private void saveSiegeGuard(int x, int y, int z, int heading, int npcId, int isHire)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("Insert Into castle_siege_guards (castleId, npcId, x, y, z, heading, respawnDelay, isHired) Values (?, ?, ?, ?, ?, ?, ?, ?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("Insert Into castle_siege_guards (castleId, npcId, x, y, z, heading, respawnDelay, isHired) Values (?, ?, ?, ?, ?, ?, ?, ?)");
 			statement.setInt(1, getCastle().getCastleId());
 			statement.setInt(2, npcId);
 			statement.setInt(3, x);
@@ -265,7 +261,6 @@ public class SiegeGuardManager
 			statement.setInt(7, (isHire == 1 ? 0 : 600));
 			statement.setInt(8, isHire);
 			statement.execute();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 8 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/SiegeManager.java

@@ -130,21 +130,19 @@ public class SiegeManager
 		}
 		
 		boolean register = false;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM siege_clans where clan_id=? and castle_id=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM siege_clans where clan_id=? and castle_id=?");
 			statement.setInt(1, clan.getClanId());
 			statement.setInt(2, castleid);
-			ResultSet rs = statement.executeQuery();
-			
-			while (rs.next())
+			try (ResultSet rs = statement.executeQuery())
 			{
-				register = true;
-				break;
+				while (rs.next())
+				{
+					register = true;
+					break;
+				}
 			}
-			
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 25 - 34
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java

@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.Calendar;
 import java.util.Collection;
 import java.util.List;
@@ -797,11 +798,11 @@ public class TerritoryWarManager implements Siegable
 	{
 		final String query = delete ? DELETE : INSERT;
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement(query))
+			PreparedStatement ps = con.prepareStatement(query))
 		{
-			statement.setInt(1, castleId);
-			statement.setInt(2, objId);
-			statement.execute();
+			ps.setInt(1, castleId);
+			ps.setInt(2, objId);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -811,18 +812,18 @@ public class TerritoryWarManager implements Siegable
 	
 	private void updateTerritoryData(Territory ter)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		StringBuilder wardList = new StringBuilder();
+		for (int i : ter.getOwnedWardIds())
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE territories SET ownedWardIds=? WHERE territoryId=?");
-			StringBuilder wardList = new StringBuilder();
-			for (int i : ter.getOwnedWardIds())
-			{
-				wardList.append(i + ";");
-			}
-			statement.setString(1, wardList.toString());
-			statement.setInt(2, ter.getTerritoryId());
-			statement.execute();
-			statement.close();
+			wardList.append(i + ";");
+		}
+		
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE territories SET ownedWardIds=? WHERE territoryId=?"))
+		{
+			ps.setString(1, wardList.toString());
+			ps.setInt(2, ter.getTerritoryId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -855,11 +856,10 @@ public class TerritoryWarManager implements Siegable
 		MINTWBADGEFORSTRIDERS = Integer.decode(territoryWarSettings.getProperty("MinTerritoryBadgeForStriders", "50"));
 		MINTWBADGEFORBIGSTRIDER = Integer.decode(territoryWarSettings.getProperty("MinTerritoryBadgeForBigStrider", "80"));
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM territory_spawnlist"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM territory_spawnlist");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				int castleId = rs.getInt("castleId");
@@ -884,20 +884,16 @@ public class TerritoryWarManager implements Siegable
 						_log.warning(getClass().getSimpleName() + ": Unknown npc type for " + rs.getInt("id"));
 				}
 			}
-			
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
 			_log.log(Level.WARNING, getClass().getSimpleName() + ": SpawnList error: " + e.getMessage(), e);
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM territories"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM territories");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				int castleId = rs.getInt("castleId");
@@ -926,19 +922,16 @@ public class TerritoryWarManager implements Siegable
 					}
 				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
 			_log.log(Level.WARNING, getClass().getSimpleName() + ": territory list error(): " + e.getMessage(), e);
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM territory_registrations"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM territory_registrations");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				int castleId = rs.getInt("castleId");
@@ -960,8 +953,6 @@ public class TerritoryWarManager implements Siegable
 					_registeredMercenaries.get(castleId).add(registeredId);
 				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 2 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/games/Lottery.java

@@ -89,14 +89,13 @@ public class Lottery
 	public void increasePrize(long count)
 	{
 		_prize += count;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(UPDATE_PRICE))
 		{
-			PreparedStatement statement = con.prepareStatement(UPDATE_PRICE);
 			statement.setLong(1, getPrize());
 			statement.setLong(2, getPrize());
 			statement.setInt(3, getId());
 			statement.execute();
-			statement.close();
 		}
 		catch (SQLException e)
 		{

+ 17 - 17
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -8627,31 +8627,31 @@ public final class L2PcInstance extends L2Playable
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			PreparedStatement statement;
-			
 			if ((oldSkill != null) && (newSkill != null))
 			{
-				statement = con.prepareStatement(UPDATE_CHARACTER_SKILL_LEVEL);
-				statement.setInt(1, newSkill.getLevel());
-				statement.setInt(2, oldSkill.getId());
-				statement.setInt(3, getObjectId());
-				statement.setInt(4, classIndex);
-				statement.execute();
-				statement.close();
+				try (PreparedStatement ps = con.prepareStatement(UPDATE_CHARACTER_SKILL_LEVEL))
+				{
+					ps.setInt(1, newSkill.getLevel());
+					ps.setInt(2, oldSkill.getId());
+					ps.setInt(3, getObjectId());
+					ps.setInt(4, classIndex);
+					ps.execute();
+				}
 			}
 			else if (newSkill != null)
 			{
-				statement = con.prepareStatement(ADD_NEW_SKILL);
-				statement.setInt(1, getObjectId());
-				statement.setInt(2, newSkill.getId());
-				statement.setInt(3, newSkill.getLevel());
-				statement.setInt(4, classIndex);
-				statement.execute();
-				statement.close();
+				try (PreparedStatement ps = con.prepareStatement(ADD_NEW_SKILL))
+				{
+					ps.setInt(1, getObjectId());
+					ps.setInt(2, newSkill.getId());
+					ps.setInt(3, newSkill.getLevel());
+					ps.setInt(4, classIndex);
+					ps.execute();
+				}
 			}
 			else
 			{
-				_log.warning("could not store new skill. its NULL");
+				_log.warning("Could not store new skill, it's null!");
 			}
 		}
 		catch (Exception e)

+ 72 - 78
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Castle.java

@@ -17,6 +17,7 @@ package com.l2jserver.gameserver.model.entity;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
@@ -232,15 +233,15 @@ public class Castle
 		public void dbSave()
 		{
 			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-				PreparedStatement statement = con.prepareStatement("REPLACE INTO castle_functions (castle_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)"))
+				PreparedStatement ps = con.prepareStatement("REPLACE INTO castle_functions (castle_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)"))
 			{
-				statement.setInt(1, getCastleId());
-				statement.setInt(2, getType());
-				statement.setInt(3, getLvl());
-				statement.setInt(4, getLease());
-				statement.setLong(5, getRate());
-				statement.setLong(6, getEndTime());
-				statement.execute();
+				ps.setInt(1, getCastleId());
+				ps.setInt(2, getType());
+				ps.setInt(3, getLvl());
+				ps.setInt(4, getLease());
+				ps.setLong(5, getRate());
+				ps.setLong(6, getEndTime());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -389,11 +390,11 @@ public class Castle
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE castle SET treasury = ? WHERE id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE castle SET treasury = ? WHERE id = ?"))
 		{
-			statement.setLong(1, getTreasury());
-			statement.setInt(2, getCastleId());
-			statement.execute();
+			ps.setLong(1, getTreasury());
+			ps.setInt(2, getCastleId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -657,11 +658,11 @@ public class Castle
 		_taxRate = _taxPercent / 100.0;
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE castle SET taxPercent = ? WHERE id = ?"))
+			PreparedStatement ps = con.prepareStatement("UPDATE castle SET taxPercent = ? WHERE id = ?"))
 		{
-			statement.setInt(1, taxPercent);
-			statement.setInt(2, getCastleId());
-			statement.execute();
+			ps.setInt(1, taxPercent);
+			ps.setInt(2, getCastleId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -777,10 +778,10 @@ public class Castle
 	private void loadFunctions()
 	{
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM castle_functions WHERE castle_id = ?"))
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM castle_functions WHERE castle_id = ?"))
 		{
-			statement.setInt(1, getCastleId());
-			try (ResultSet rs = statement.executeQuery())
+			ps.setInt(1, getCastleId());
+			try (ResultSet rs = ps.executeQuery())
 			{
 				while (rs.next())
 				{
@@ -802,11 +803,11 @@ public class Castle
 	{
 		_function.remove(functionType);
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("DELETE FROM castle_functions WHERE castle_id=? AND type=?"))
+			PreparedStatement ps = con.prepareStatement("DELETE FROM castle_functions WHERE castle_id=? AND type=?"))
 		{
-			statement.setInt(1, getCastleId());
-			statement.setInt(2, functionType);
-			statement.execute();
+			ps.setInt(1, getCastleId());
+			ps.setInt(2, functionType);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -876,23 +877,21 @@ public class Castle
 	// This method loads castle door upgrade data from database
 	private void loadDoorUpgrade()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		StringBuilder doorIds = new StringBuilder(100);
+		for (L2DoorInstance door : getDoors())
+		{
+			doorIds.append(door.getDoorId()).append(',');
+		}
+		doorIds.deleteCharAt(doorIds.length() - 1);
+		
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement();
+			ResultSet rs = s.executeQuery("SELECT * FROM castle_doorupgrade WHERE doorId IN (" + doorIds.toString() + ")"))
 		{
-			StringBuilder doorIds = new StringBuilder(100);
-			for (L2DoorInstance door : getDoors())
-			{
-				doorIds.append(door.getDoorId()).append(',');
-			}
-			doorIds.deleteCharAt(doorIds.length() - 1);
-			PreparedStatement statement = con.prepareStatement("Select * from castle_doorupgrade where doorId in (" + doorIds.toString() + ")");
-			ResultSet rs = statement.executeQuery();
-			
 			while (rs.next())
 			{
 				upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -902,17 +901,17 @@ public class Castle
 	
 	private void removeDoorUpgrade()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		StringBuilder doorIds = new StringBuilder(100);
+		for (L2DoorInstance door : getDoors())
 		{
-			StringBuilder doorIds = new StringBuilder(100);
-			for (L2DoorInstance door : getDoors())
-			{
-				doorIds.append(door.getDoorId()).append(',');
-			}
-			doorIds.deleteCharAt(doorIds.length() - 1);
-			PreparedStatement statement = con.prepareStatement("delete from castle_doorupgrade where doorId in (" + doorIds.toString() + ")");
-			statement.execute();
-			statement.close();
+			doorIds.append(door.getDoorId()).append(',');
+		}
+		doorIds.deleteCharAt(doorIds.length() - 1);
+		
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			Statement s = con.createStatement())
+		{
+			s.executeQuery("DELETE FROM castle_doorupgrade WHERE doorId IN (" + doorIds.toString() + ")");
 		}
 		catch (Exception e)
 		{
@@ -922,15 +921,14 @@ public class Castle
 	
 	private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("INSERT INTO castle_doorupgrade (doorId, hp, pDef, mDef) values (?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO castle_doorupgrade (doorId, hp, pDef, mDef) values (?,?,?,?)");
-			statement.setInt(1, doorId);
-			statement.setInt(2, hp);
-			statement.setInt(3, pDef);
-			statement.setInt(4, mDef);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, doorId);
+			ps.setInt(2, hp);
+			ps.setInt(3, pDef);
+			ps.setInt(4, mDef);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1393,15 +1391,14 @@ public class Castle
 	
 	public void updateCrop(int cropId, long amount, int period)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(CASTLE_UPDATE_CROP))
 		{
-			PreparedStatement statement = con.prepareStatement(CASTLE_UPDATE_CROP);
-			statement.setLong(1, amount);
-			statement.setInt(2, cropId);
-			statement.setInt(3, getCastleId());
-			statement.setInt(4, period);
-			statement.execute();
-			statement.close();
+			ps.setLong(1, amount);
+			ps.setInt(2, cropId);
+			ps.setInt(3, getCastleId());
+			ps.setInt(4, period);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1411,15 +1408,14 @@ public class Castle
 	
 	public void updateSeed(int seedId, long amount, int period)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement(CASTLE_UPDATE_SEED))
 		{
-			PreparedStatement statement = con.prepareStatement(CASTLE_UPDATE_SEED);
-			statement.setLong(1, amount);
-			statement.setInt(2, seedId);
-			statement.setInt(3, getCastleId());
-			statement.setInt(4, period);
-			statement.execute();
-			statement.close();
+			ps.setLong(1, amount);
+			ps.setInt(2, seedId);
+			ps.setInt(3, getCastleId());
+			ps.setInt(4, period);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1468,13 +1464,12 @@ public class Castle
 	
 	public void updateShowNpcCrest()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE castle SET showNpcCrest = ? WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE castle SET showNpcCrest = ? WHERE id = ?");
-			statement.setString(1, String.valueOf(getShowNpcCrest()));
-			statement.setInt(2, getCastleId());
-			statement.execute();
-			statement.close();
+			ps.setString(1, String.valueOf(getShowNpcCrest()));
+			ps.setInt(2, getCastleId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1578,13 +1573,12 @@ public class Castle
 	{
 		_bloodAlliance = count;
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement("UPDATE castle SET bloodAlliance = ? WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE castle SET bloodAlliance = ? WHERE id = ?");
 			statement.setInt(1, _bloodAlliance);
 			statement.setInt(2, getCastleId());
 			statement.execute();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 22 - 24
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/ClanHall.java

@@ -185,17 +185,16 @@ public abstract class ClanHall
 		
 		public void dbSave()
 		{
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement ps = con.prepareStatement("REPLACE INTO clanhall_functions (hall_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)"))
 			{
-				PreparedStatement statement = con.prepareStatement("REPLACE INTO clanhall_functions (hall_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)");
-				statement.setInt(1, getId());
-				statement.setInt(2, getType());
-				statement.setInt(3, getLvl());
-				statement.setInt(4, getLease());
-				statement.setLong(5, getRate());
-				statement.setLong(6, getEndTime());
-				statement.execute();
-				statement.close();
+				ps.setInt(1, getId());
+				ps.setInt(2, getType());
+				ps.setInt(3, getLvl());
+				ps.setInt(4, getLease());
+				ps.setLong(5, getRate());
+				ps.setLong(6, getEndTime());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -448,17 +447,17 @@ public abstract class ClanHall
 	/** Load All Functions */
 	protected void loadFunctions()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM clanhall_functions WHERE hall_id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM clanhall_functions WHERE hall_id = ?");
-			statement.setInt(1, getId());
-			ResultSet rs = statement.executeQuery();
-			while (rs.next())
+			ps.setInt(1, getId());
+			try (ResultSet rs = ps.executeQuery())
 			{
-				_functions.put(rs.getInt("type"), new ClanHallFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"), 0, rs.getLong("rate"), rs.getLong("endTime"), true));
+				while (rs.next())
+				{
+					_functions.put(rs.getInt("type"), new ClanHallFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"), 0, rs.getLong("rate"), rs.getLong("endTime"), true));
+				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -473,13 +472,12 @@ public abstract class ClanHall
 	public void removeFunction(int functionType)
 	{
 		_functions.remove(functionType);
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM clanhall_functions WHERE hall_id=? AND type=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM clanhall_functions WHERE hall_id=? AND type=?");
-			statement.setInt(1, getId());
-			statement.setInt(2, functionType);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getId());
+			ps.setInt(2, functionType);
+			ps.execute();
 		}
 		catch (Exception e)
 		{

+ 35 - 39
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Couple.java

@@ -43,26 +43,25 @@ public class Couple
 	{
 		_Id = coupleId;
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM mods_wedding WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM mods_wedding WHERE id = ?");
-			statement.setInt(1, _Id);
-			ResultSet rs = statement.executeQuery();
-			
-			while (rs.next())
+			ps.setInt(1, _Id);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				_player1Id = rs.getInt("player1Id");
-				_player2Id = rs.getInt("player2Id");
-				_maried = rs.getBoolean("married");
-				
-				_affiancedDate = Calendar.getInstance();
-				_affiancedDate.setTimeInMillis(rs.getLong("affianceDate"));
-				
-				_weddingDate = Calendar.getInstance();
-				_weddingDate.setTimeInMillis(rs.getLong("weddingDate"));
+				while (rs.next())
+				{
+					_player1Id = rs.getInt("player1Id");
+					_player2Id = rs.getInt("player2Id");
+					_maried = rs.getBoolean("married");
+					
+					_affiancedDate = Calendar.getInstance();
+					_affiancedDate.setTimeInMillis(rs.getLong("affianceDate"));
+					
+					_weddingDate = Calendar.getInstance();
+					_weddingDate.setTimeInMillis(rs.getLong("weddingDate"));
+				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -84,18 +83,17 @@ public class Couple
 		_weddingDate = Calendar.getInstance();
 		_weddingDate.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("INSERT INTO mods_wedding (id, player1Id, player2Id, married, affianceDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)"))
 		{
 			_Id = IdFactory.getInstance().getNextId();
-			PreparedStatement statement = con.prepareStatement("INSERT INTO mods_wedding (id, player1Id, player2Id, married, affianceDate, weddingDate) VALUES (?, ?, ?, ?, ?, ?)");
-			statement.setInt(1, _Id);
-			statement.setInt(2, _player1Id);
-			statement.setInt(3, _player2Id);
-			statement.setBoolean(4, false);
-			statement.setLong(5, _affiancedDate.getTimeInMillis());
-			statement.setLong(6, _weddingDate.getTimeInMillis());
-			statement.execute();
-			statement.close();
+			ps.setInt(1, _Id);
+			ps.setInt(2, _player1Id);
+			ps.setInt(3, _player2Id);
+			ps.setBoolean(4, false);
+			ps.setLong(5, _affiancedDate.getTimeInMillis());
+			ps.setLong(6, _weddingDate.getTimeInMillis());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -105,15 +103,14 @@ public class Couple
 	
 	public void marry()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE mods_wedding set married = ?, weddingDate = ? where id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE mods_wedding set married = ?, weddingDate = ? where id = ?");
-			statement.setBoolean(1, true);
+			ps.setBoolean(1, true);
 			_weddingDate = Calendar.getInstance();
-			statement.setLong(2, _weddingDate.getTimeInMillis());
-			statement.setInt(3, _Id);
-			statement.execute();
-			statement.close();
+			ps.setLong(2, _weddingDate.getTimeInMillis());
+			ps.setInt(3, _Id);
+			ps.execute();
 			_maried = true;
 		}
 		catch (Exception e)
@@ -124,12 +121,11 @@ public class Couple
 	
 	public void divorce()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM mods_wedding WHERE id=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM mods_wedding WHERE id=?");
-			statement.setInt(1, _Id);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, _Id);
+			ps.execute();
 		}
 		catch (Exception e)
 		{

+ 183 - 204
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/Fort.java

@@ -225,17 +225,16 @@ public class Fort
 		
 		public void dbSave()
 		{
-			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement ps = con.prepareStatement("REPLACE INTO fort_functions (fort_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)"))
 			{
-				PreparedStatement statement = con.prepareStatement("REPLACE INTO fort_functions (fort_id, type, lvl, lease, rate, endTime) VALUES (?,?,?,?,?,?)");
-				statement.setInt(1, getFortId());
-				statement.setInt(2, getType());
-				statement.setInt(3, getLvl());
-				statement.setInt(4, getLease());
-				statement.setLong(5, getRate());
-				statement.setLong(6, getEndTime());
-				statement.execute();
-				statement.close();
+				ps.setInt(1, getFortId());
+				ps.setInt(2, getType());
+				ps.setInt(3, getLvl());
+				ps.setInt(4, getLease());
+				ps.setLong(5, getRate());
+				ps.setLong(6, getEndTime());
+				ps.execute();
 			}
 			catch (Exception e)
 			{
@@ -567,14 +566,13 @@ public class Fort
 	
 	public void saveFortVariables()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE fort SET blood=?, supplyLvL=? WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE fort SET blood=?, supplyLvL=? WHERE id = ?");
-			statement.setInt(1, _blood);
-			statement.setInt(2, _supplyLvL);
-			statement.setInt(3, getFortId());
-			statement.execute();
-			statement.close();
+			ps.setInt(1, _blood);
+			ps.setInt(2, _supplyLvL);
+			ps.setInt(3, getFortId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -636,32 +634,29 @@ public class Fort
 	// This method loads fort
 	private void load()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM fort WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM fort WHERE id = ?");
-			statement.setInt(1, getFortId());
-			ResultSet rs = statement.executeQuery();
+			ps.setInt(1, getFortId());
 			int ownerId = 0;
-			
-			while (rs.next())
+			try (ResultSet rs = ps.executeQuery())
 			{
-				_name = rs.getString("name");
-				
-				_siegeDate = Calendar.getInstance();
-				_lastOwnedTime = Calendar.getInstance();
-				_siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
-				_lastOwnedTime.setTimeInMillis(rs.getLong("lastOwnedTime"));
-				ownerId = rs.getInt("owner");
-				_fortType = rs.getInt("fortType");
-				_state = rs.getInt("state");
-				_castleId = rs.getInt("castleId");
-				_blood = rs.getInt("blood");
-				_supplyLvL = rs.getInt("supplyLvL");
+				while (rs.next())
+				{
+					_name = rs.getString("name");
+					
+					_siegeDate = Calendar.getInstance();
+					_lastOwnedTime = Calendar.getInstance();
+					_siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
+					_lastOwnedTime.setTimeInMillis(rs.getLong("lastOwnedTime"));
+					ownerId = rs.getInt("owner");
+					_fortType = rs.getInt("fortType");
+					_state = rs.getInt("state");
+					_castleId = rs.getInt("castleId");
+					_blood = rs.getInt("blood");
+					_supplyLvL = rs.getInt("supplyLvL");
+				}
 			}
-			
-			rs.close();
-			statement.close();
-			
 			if (ownerId > 0)
 			{
 				L2Clan clan = ClanTable.getInstance().getClan(ownerId); // Try to find clan instance
@@ -702,19 +697,17 @@ public class Fort
 	/** Load All Functions */
 	private void loadFunctions()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM fort_functions WHERE fort_id = ?"))
 		{
-			PreparedStatement statement;
-			ResultSet rs;
-			statement = con.prepareStatement("SELECT * FROM fort_functions WHERE fort_id = ?");
-			statement.setInt(1, getFortId());
-			rs = statement.executeQuery();
-			while (rs.next())
+			ps.setInt(1, getFortId());
+			try (ResultSet rs = ps.executeQuery())
 			{
-				_function.put(rs.getInt("type"), new FortFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"), 0, rs.getLong("rate"), rs.getLong("endTime"), true));
+				while (rs.next())
+				{
+					_function.put(rs.getInt("type"), new FortFunction(rs.getInt("type"), rs.getInt("lvl"), rs.getInt("lease"), 0, rs.getLong("rate"), rs.getLong("endTime"), true));
+				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -729,13 +722,12 @@ public class Fort
 	public void removeFunction(int functionType)
 	{
 		_function.remove(functionType);
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM fort_functions WHERE fort_id=? AND type=?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM fort_functions WHERE fort_id=? AND type=?");
-			statement.setInt(1, getFortId());
-			statement.setInt(2, functionType);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getFortId());
+			ps.setInt(2, functionType);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -832,18 +824,17 @@ public class Fort
 	// This method loads fort door upgrade data from database
 	private void loadDoorUpgrade()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM fort_doorupgrade WHERE fortId = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_doorupgrade WHERE fortId = ?");
-			statement.setInt(1, getFortId());
-			ResultSet rs = statement.executeQuery();
-			
-			while (rs.next())
+			ps.setInt(1, getFortId());
+			try (ResultSet rs = ps.executeQuery())
 			{
-				upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
+				while (rs.next())
+				{
+					upgradeDoor(rs.getInt("id"), rs.getInt("hp"), rs.getInt("pDef"), rs.getInt("mDef"));
+				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -853,12 +844,11 @@ public class Fort
 	
 	private void removeDoorUpgrade()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("DELETE FROM fort_doorupgrade WHERE WHERE fortId = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM fort_doorupgrade WHERE WHERE fortId = ?");
-			statement.setInt(1, getFortId());
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getFortId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -868,15 +858,14 @@ public class Fort
 	
 	private void saveDoorUpgrade(int doorId, int hp, int pDef, int mDef)
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("INSERT INTO fort_doorupgrade (doorId, hp, pDef, mDef) VALUES (?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("INSERT INTO fort_doorupgrade (doorId, hp, pDef, mDef) VALUES (?,?,?,?)");
-			statement.setInt(1, doorId);
-			statement.setInt(2, hp);
-			statement.setInt(3, pDef);
-			statement.setInt(4, mDef);
-			statement.execute();
-			statement.close();
+			ps.setInt(1, doorId);
+			ps.setInt(2, hp);
+			ps.setInt(3, pDef);
+			ps.setInt(4, mDef);
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -898,17 +887,16 @@ public class Fort
 			_lastOwnedTime.setTimeInMillis(0);
 		}
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
-		{
-			PreparedStatement statement = con.prepareStatement("UPDATE fort SET owner=?,lastOwnedTime=?,state=?,castleId=?,blood=? WHERE id = ?");
-			statement.setInt(1, clanId);
-			statement.setLong(2, _lastOwnedTime.getTimeInMillis());
-			statement.setInt(3, 0);
-			statement.setInt(4, 0);
-			statement.setInt(5, getBloodOathReward());
-			statement.setInt(6, getFortId());
-			statement.execute();
-			statement.close();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE fort SET owner=?,lastOwnedTime=?,state=?,castleId=?,blood=? WHERE id = ?"))
+		{
+			ps.setInt(1, clanId);
+			ps.setLong(2, _lastOwnedTime.getTimeInMillis());
+			ps.setInt(3, 0);
+			ps.setInt(4, 0);
+			ps.setInt(5, getBloodOathReward());
+			ps.setInt(6, getFortId());
+			ps.execute();
 			
 			// Announce to clan members
 			if (clan != null)
@@ -1116,14 +1104,13 @@ public class Fort
 	{
 		_state = state;
 		_castleId = castleId;
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("UPDATE fort SET state=?,castleId=? WHERE id = ?"))
 		{
-			PreparedStatement statement = con.prepareStatement("UPDATE fort SET state=?,castleId=? WHERE id = ?");
-			statement.setInt(1, getFortState());
-			statement.setInt(2, getCastleId());
-			statement.setInt(3, getFortId());
-			statement.execute();
-			statement.close();
+			ps.setInt(1, getFortState());
+			ps.setInt(2, getCastleId());
+			ps.setInt(3, getFortId());
+			ps.execute();
 		}
 		catch (Exception e)
 		{
@@ -1231,44 +1218,40 @@ public class Fort
 	
 	private void initNpcs()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT * FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? "))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT * FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ");
-			statement.setInt(1, getFortId());
-			statement.setInt(2, 0);
-			ResultSet rset = statement.executeQuery();
-			
-			L2Spawn spawnDat;
-			L2NpcTemplate template;
-			
-			while (rset.next())
+			ps.setInt(1, getFortId());
+			ps.setInt(2, 0);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
-				if (template != null)
+				L2Spawn spawnDat;
+				L2NpcTemplate template;
+				while (rs.next())
 				{
-					spawnDat = new L2Spawn(template);
-					spawnDat.setAmount(1);
-					spawnDat.setLocx(rset.getInt("x"));
-					spawnDat.setLocy(rset.getInt("y"));
-					spawnDat.setLocz(rset.getInt("z"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(60);
-					SpawnTable.getInstance().addNewSpawn(spawnDat, false);
-					spawnDat.doSpawn();
-					spawnDat.startRespawn();
-				}
-				else
-				{
-					_log.warning("Fort " + getFortId() + " initNpcs: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
+					template = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
+					if (template != null)
+					{
+						spawnDat = new L2Spawn(template);
+						spawnDat.setAmount(1);
+						spawnDat.setLocx(rs.getInt("x"));
+						spawnDat.setLocy(rs.getInt("y"));
+						spawnDat.setLocz(rs.getInt("z"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(60);
+						SpawnTable.getInstance().addNewSpawn(spawnDat, false);
+						spawnDat.doSpawn();
+						spawnDat.startRespawn();
+					}
+					else
+					{
+						_log.warning("Fort " + getFortId() + " initNpcs: Data missing in NPC table for ID: " + rs.getInt("npcId") + ".");
+					}
 				}
 			}
-			
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "Fort " + getFortId() + " initNpcs: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}
@@ -1276,40 +1259,38 @@ public class Fort
 	private void initSiegeNpcs()
 	{
 		_siegeNpcs.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
-			statement.setInt(1, getFortId());
-			statement.setInt(2, 2);
-			ResultSet rset = statement.executeQuery();
-			
-			L2Spawn spawnDat;
-			L2NpcTemplate template;
-			while (rset.next())
+			ps.setInt(1, getFortId());
+			ps.setInt(2, 2);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
-				if (template != null)
-				{
-					spawnDat = new L2Spawn(template);
-					spawnDat.setAmount(1);
-					spawnDat.setLocx(rset.getInt("x"));
-					spawnDat.setLocy(rset.getInt("y"));
-					spawnDat.setLocz(rset.getInt("z"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(60);
-					_siegeNpcs.add(spawnDat);
-				}
-				else
+				L2Spawn spawnDat;
+				L2NpcTemplate template;
+				while (rs.next())
 				{
-					_log.warning("Fort " + getFortId() + " initSiegeNpcs: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
+					template = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
+					if (template != null)
+					{
+						spawnDat = new L2Spawn(template);
+						spawnDat.setAmount(1);
+						spawnDat.setLocx(rs.getInt("x"));
+						spawnDat.setLocy(rs.getInt("y"));
+						spawnDat.setLocz(rs.getInt("z"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(60);
+						_siegeNpcs.add(spawnDat);
+					}
+					else
+					{
+						_log.warning("Fort " + getFortId() + " initSiegeNpcs: Data missing in NPC table for ID: " + rs.getInt("npcId") + ".");
+					}
 				}
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
-			// problem with initializing spawn, go to next one
 			_log.log(Level.WARNING, "Fort " + getFortId() + " initSiegeNpcs: Spawn could not be initialized: " + e.getMessage(), e);
 		}
 	}
@@ -1317,36 +1298,35 @@ public class Fort
 	private void initNpcCommanders()
 	{
 		_npcCommanders.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
-			statement.setInt(1, getFortId());
-			statement.setInt(2, 1);
-			ResultSet rset = statement.executeQuery();
-			
-			L2Spawn spawnDat;
-			L2NpcTemplate template;
-			while (rset.next())
+			ps.setInt(1, getFortId());
+			ps.setInt(2, 1);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				template = NpcTable.getInstance().getTemplate(rset.getInt("npcId"));
-				if (template != null)
-				{
-					spawnDat = new L2Spawn(template);
-					spawnDat.setAmount(1);
-					spawnDat.setLocx(rset.getInt("x"));
-					spawnDat.setLocy(rset.getInt("y"));
-					spawnDat.setLocz(rset.getInt("z"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(60);
-					_npcCommanders.add(spawnDat);
-				}
-				else
+				L2Spawn spawnDat;
+				L2NpcTemplate template;
+				while (rs.next())
 				{
-					_log.warning("Fort " + getFortId() + " initNpcCommanders: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
+					template = NpcTable.getInstance().getTemplate(rs.getInt("npcId"));
+					if (template != null)
+					{
+						spawnDat = new L2Spawn(template);
+						spawnDat.setAmount(1);
+						spawnDat.setLocx(rs.getInt("x"));
+						spawnDat.setLocy(rs.getInt("y"));
+						spawnDat.setLocz(rs.getInt("z"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(60);
+						_npcCommanders.add(spawnDat);
+					}
+					else
+					{
+						_log.warning("Fort " + getFortId() + " initNpcCommanders: Data missing in NPC table for ID: " + rs.getInt("npcId") + ".");
+					}
 				}
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -1359,39 +1339,38 @@ public class Fort
 	{
 		_specialEnvoys.clear();
 		_envoyCastles.clear();
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT id, npcId, x, y, z, heading, castleId FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id"))
 		{
-			PreparedStatement statement = con.prepareStatement("SELECT id, npcId, x, y, z, heading, castleId FROM fort_spawnlist WHERE fortId = ? AND spawnType = ? ORDER BY id");
-			statement.setInt(1, getFortId());
-			statement.setInt(2, 3);
-			ResultSet rset = statement.executeQuery();
-			
-			L2Spawn spawnDat;
-			L2NpcTemplate template;
-			while (rset.next())
+			ps.setInt(1, getFortId());
+			ps.setInt(2, 3);
+			try (ResultSet rs = ps.executeQuery())
 			{
-				int castleId = rset.getInt("castleId");
-				int npcId = rset.getInt("npcId");
-				template = NpcTable.getInstance().getTemplate(npcId);
-				if (template != null)
-				{
-					spawnDat = new L2Spawn(template);
-					spawnDat.setAmount(1);
-					spawnDat.setLocx(rset.getInt("x"));
-					spawnDat.setLocy(rset.getInt("y"));
-					spawnDat.setLocz(rset.getInt("z"));
-					spawnDat.setHeading(rset.getInt("heading"));
-					spawnDat.setRespawnDelay(60);
-					_specialEnvoys.add(spawnDat);
-					_envoyCastles.put(npcId, castleId);
-				}
-				else
+				L2Spawn spawnDat;
+				L2NpcTemplate template;
+				while (rs.next())
 				{
-					_log.warning("Fort " + getFortId() + " initSpecialEnvoys: Data missing in NPC table for ID: " + rset.getInt("npcId") + ".");
+					int castleId = rs.getInt("castleId");
+					int npcId = rs.getInt("npcId");
+					template = NpcTable.getInstance().getTemplate(npcId);
+					if (template != null)
+					{
+						spawnDat = new L2Spawn(template);
+						spawnDat.setAmount(1);
+						spawnDat.setLocx(rs.getInt("x"));
+						spawnDat.setLocy(rs.getInt("y"));
+						spawnDat.setLocz(rs.getInt("z"));
+						spawnDat.setHeading(rs.getInt("heading"));
+						spawnDat.setRespawnDelay(60);
+						_specialEnvoys.add(spawnDat);
+						_envoyCastles.put(npcId, castleId);
+					}
+					else
+					{
+						_log.warning("Fort " + getFortId() + " initSpecialEnvoys: Data missing in NPC table for ID: " + rs.getInt("npcId") + ".");
+					}
 				}
 			}
-			rset.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 9 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/FortSiege.java

@@ -1045,18 +1045,18 @@ public class FortSiege implements Siegable
 	/** Load siege clans. */
 	private void loadSiegeClan()
 	{
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		getAttackerClans().clear();
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement ps = con.prepareStatement("SELECT clan_id FROM fortsiege_clans WHERE fort_id=?"))
 		{
-			getAttackerClans().clear();
-			PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM fortsiege_clans WHERE fort_id=?");
-			statement.setInt(1, getFort().getFortId());
-			ResultSet rs = statement.executeQuery();
-			while (rs.next())
+			ps.setInt(1, getFort().getFortId());
+			try (ResultSet rs = ps.executeQuery())
 			{
-				addAttacker(rs.getInt("clan_id"));
+				while (rs.next())
+				{
+					addAttacker(rs.getInt("clan_id"));
+				}
 			}
-			rs.close();
-			statement.close();
 		}
 		catch (Exception e)
 		{

+ 83 - 81
L2J_Server_BETA/java/com/l2jserver/gameserver/model/items/instance/L2ItemInstance.java

@@ -953,10 +953,10 @@ public final class L2ItemInstance extends L2Object
 		_augmentation = null;
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("DELETE FROM item_attributes WHERE itemId = ?"))
+			PreparedStatement ps = con.prepareStatement("DELETE FROM item_attributes WHERE itemId = ?"))
 		{
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
+			ps.setInt(1, getObjectId());
+			ps.executeUpdate();
 		}
 		catch (Exception e)
 		{
@@ -1007,32 +1007,30 @@ public final class L2ItemInstance extends L2Object
 	
 	private void updateItemAttributes(Connection con)
 	{
-		try
+		try (PreparedStatement ps = con.prepareStatement("REPLACE INTO item_attributes VALUES(?,?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("REPLACE INTO item_attributes VALUES(?,?,?,?)");
-			statement.setInt(1, getObjectId());
+			ps.setInt(1, getObjectId());
 			if (_augmentation == null)
 			{
-				statement.setInt(2, -1);
-				statement.setInt(3, -1);
-				statement.setInt(4, -1);
+				ps.setInt(2, -1);
+				ps.setInt(3, -1);
+				ps.setInt(4, -1);
 			}
 			else
 			{
-				statement.setInt(2, _augmentation.getAttributes());
+				ps.setInt(2, _augmentation.getAttributes());
 				if (_augmentation.getSkill() == null)
 				{
-					statement.setInt(3, 0);
-					statement.setInt(4, 0);
+					ps.setInt(3, 0);
+					ps.setInt(4, 0);
 				}
 				else
 				{
-					statement.setInt(3, _augmentation.getSkill().getId());
-					statement.setInt(4, _augmentation.getSkill().getLevel());
+					ps.setInt(3, _augmentation.getSkill().getId());
+					ps.setInt(4, _augmentation.getSkill().getLevel());
 				}
 			}
-			statement.executeUpdate();
-			statement.close();
+			ps.executeUpdate();
 		}
 		catch (SQLException e)
 		{
@@ -1042,30 +1040,31 @@ public final class L2ItemInstance extends L2Object
 	
 	private void updateItemElements(Connection con)
 	{
-		try
+		try (PreparedStatement ps = con.prepareStatement("DELETE FROM item_elementals WHERE itemId = ?"))
+		{
+			ps.setInt(1, getObjectId());
+			ps.executeUpdate();
+		}
+		catch (SQLException e)
+		{
+			_log.log(Level.SEVERE, "Could not update elementals for item: " + this + " from DB:", e);
+		}
+		
+		if (_elementals == null)
+		{
+			return;
+		}
+		
+		try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_elementals VALUES(?,?,?)"))
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM item_elementals WHERE itemId = ?");
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
-			statement.close();
-			
-			if (_elementals == null)
-			{
-				return;
-			}
-			
-			statement = con.prepareStatement("INSERT INTO item_elementals VALUES(?,?,?)");
-			
 			for (Elementals elm : _elementals)
 			{
-				statement.setInt(1, getObjectId());
-				statement.setByte(2, elm.getElement());
-				statement.setInt(3, elm.getValue());
-				statement.executeUpdate();
-				statement.clearParameters();
+				ps.setInt(1, getObjectId());
+				ps.setByte(2, elm.getElement());
+				ps.setInt(3, elm.getValue());
+				ps.executeUpdate();
+				ps.clearParameters();
 			}
-			
-			statement.close();
 		}
 		catch (SQLException e)
 		{
@@ -1224,16 +1223,16 @@ public final class L2ItemInstance extends L2Object
 		
 		String query = (element != -1) ? "DELETE FROM item_elementals WHERE itemId = ? AND elemType = ?" : "DELETE FROM item_elementals WHERE itemId = ?";
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement(query))
+			PreparedStatement ps = con.prepareStatement(query))
 		{
 			if (element != -1)
 			{
 				// Item can have still others
-				statement.setInt(2, element);
+				ps.setInt(2, element);
 			}
 			
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
+			ps.setInt(1, getObjectId());
+			ps.executeUpdate();
 		}
 		catch (Exception e)
 		{
@@ -1653,19 +1652,19 @@ public final class L2ItemInstance extends L2Object
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("UPDATE items SET owner_id=?,count=?,loc=?,loc_data=?,enchant_level=?,custom_type1=?,custom_type2=?,mana_left=?,time=? " + "WHERE object_id = ?"))
-		{
-			statement.setInt(1, _ownerId);
-			statement.setLong(2, getCount());
-			statement.setString(3, _loc.name());
-			statement.setInt(4, _locData);
-			statement.setInt(5, getEnchantLevel());
-			statement.setInt(6, getCustomType1());
-			statement.setInt(7, getCustomType2());
-			statement.setInt(8, getMana());
-			statement.setLong(9, getTime());
-			statement.setInt(10, getObjectId());
-			statement.executeUpdate();
+			PreparedStatement ps = con.prepareStatement("UPDATE items SET owner_id=?,count=?,loc=?,loc_data=?,enchant_level=?,custom_type1=?,custom_type2=?,mana_left=?,time=? " + "WHERE object_id = ?"))
+		{
+			ps.setInt(1, _ownerId);
+			ps.setLong(2, getCount());
+			ps.setString(3, _loc.name());
+			ps.setInt(4, _locData);
+			ps.setInt(5, getEnchantLevel());
+			ps.setInt(6, getCustomType1());
+			ps.setInt(7, getCustomType2());
+			ps.setInt(8, getMana());
+			ps.setLong(9, getTime());
+			ps.setInt(10, getObjectId());
+			ps.executeUpdate();
 			_existsInDb = true;
 			_storedInDb = true;
 		}
@@ -1688,21 +1687,21 @@ public final class L2ItemInstance extends L2Object
 		}
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,object_id,custom_type1,custom_type2,mana_left,time) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"))
-		{
-			statement.setInt(1, _ownerId);
-			statement.setInt(2, _itemId);
-			statement.setLong(3, getCount());
-			statement.setString(4, _loc.name());
-			statement.setInt(5, _locData);
-			statement.setInt(6, getEnchantLevel());
-			statement.setInt(7, getObjectId());
-			statement.setInt(8, _type1);
-			statement.setInt(9, _type2);
-			statement.setInt(10, getMana());
-			statement.setLong(11, getTime());
+			PreparedStatement ps = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,object_id,custom_type1,custom_type2,mana_left,time) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)"))
+		{
+			ps.setInt(1, _ownerId);
+			ps.setInt(2, _itemId);
+			ps.setLong(3, getCount());
+			ps.setString(4, _loc.name());
+			ps.setInt(5, _locData);
+			ps.setInt(6, getEnchantLevel());
+			ps.setInt(7, getObjectId());
+			ps.setInt(8, _type1);
+			ps.setInt(9, _type2);
+			ps.setInt(10, getMana());
+			ps.setLong(11, getTime());
 			
-			statement.executeUpdate();
+			ps.executeUpdate();
 			_existsInDb = true;
 			_storedInDb = true;
 			
@@ -1735,22 +1734,25 @@ public final class L2ItemInstance extends L2Object
 		
 		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE object_id = ?");
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
-			_existsInDb = false;
-			_storedInDb = false;
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM items WHERE object_id = ?"))
+			{
+				ps.setInt(1, getObjectId());
+				ps.executeUpdate();
+				_existsInDb = false;
+				_storedInDb = false;
+			}
 			
-			statement = con.prepareStatement("DELETE FROM item_attributes WHERE itemId = ?");
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM item_attributes WHERE itemId = ?"))
+			{
+				ps.setInt(1, getObjectId());
+				ps.executeUpdate();
+			}
 			
-			statement = con.prepareStatement("DELETE FROM item_elementals WHERE itemId = ?");
-			statement.setInt(1, getObjectId());
-			statement.executeUpdate();
-			statement.close();
+			try (PreparedStatement ps = con.prepareStatement("DELETE FROM item_elementals WHERE itemId = ?"))
+			{
+				ps.setInt(1, getObjectId());
+				ps.executeUpdate();
+			}
 		}
 		catch (Exception e)
 		{

+ 2 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/model/olympiad/Olympiad.java

@@ -887,9 +887,9 @@ public class Olympiad
 		
 		_heroesToBe = new L2FastList<>();
 		
-		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statement = con.prepareStatement(OLYMPIAD_GET_HEROS))
 		{
-			PreparedStatement statement = con.prepareStatement(OLYMPIAD_GET_HEROS);
 			ResultSet rset;
 			StatsSet hero;
 			L2FastList<StatsSet> soulHounds = new L2FastList<>();
@@ -926,7 +926,6 @@ public class Olympiad
 				}
 				rset.close();
 			}
-			statement.close();
 			
 			switch (soulHounds.size())
 			{