Browse Source

BETA: Reworking Connection closing by using try-with-resource:
* Using Statement instead !PreparedStatement where parameters are not required.
* Minor change in formatter settings to give proper format to try-with-resource statement.
* Fixed many resource leaks.

Zoey76 13 years ago
parent
commit
1d3ae2bd21

+ 2 - 14
L2J_DataPack_BETA/dist/game/data/scripts/conquerablehalls/RainbowSpringsChateau/RainbowSpringsChateau.java

@@ -871,10 +871,8 @@ public class RainbowSpringsChateau extends Quest
 	
 	private static void updateAttacker(int clanId, long count, boolean remove)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement;
 			if (remove)
 			{
@@ -894,18 +892,12 @@ public class RainbowSpringsChateau extends Quest
 		{
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private static void loadAttackers()
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement("SELECT * FROM rainbowsprings_attacker_list");
 			ResultSet rset = statement.executeQuery();
 			while (rset.next())
@@ -921,10 +913,6 @@ public class RainbowSpringsChateau extends Quest
 		{
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	protected static void setRegistrationEndString(long time)

+ 6 - 47
L2J_DataPack_BETA/dist/game/data/scripts/conquerablehalls/flagwar/FlagWar.java

@@ -684,16 +684,11 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 	public abstract String getFlagHtml(int flag);	
 	public abstract String getAllyHtml(int ally);
 	
-	// =============================================
-	// Database access methods
-	// =============================================
 	@Override
 	public final void loadAttackers()
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(SQL_LOAD_ATTACKERS);
 			statement.setInt(1, _hall.getId());
 			ResultSet rset = statement.executeQuery();
@@ -722,16 +717,11 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 			_log.warning(qn+".loadAttackers()->"+e.getMessage());
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private final void loadAttackerMembers(int clanId)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
 			ArrayList<Integer> listInstance = _data.get(clanId).players;
 			
@@ -741,7 +731,6 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 				return;
 			}
 			
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(SQL_LOAD_MEMEBERS);
 			statement.setInt(1, clanId);
 			ResultSet rset = statement.executeQuery();
@@ -758,18 +747,12 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 			_log.warning(qn+".loadAttackerMembers()->"+e.getMessage());
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private final void saveClan(int clanId, int flag)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(SQL_SAVE_CLAN);
 			statement.setInt(1, _hall.getId());
 			statement.setInt(2, flag);
@@ -783,18 +766,12 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 			_log.warning(qn+".saveClan()->"+e.getMessage());
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private final void saveNpc(int npc, int clanId)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(SQL_SAVE_NPC);
 			statement.setInt(1, npc);
 			statement.setInt(2, clanId);
@@ -806,18 +783,12 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 			_log.warning(qn+".saveNpc()->"+e.getMessage());
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private final void saveMember(int clanId, int objectId)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(SQL_SAVE_ATTACKER);
 			statement.setInt(1, _hall.getId());
 			statement.setInt(2, clanId);
@@ -830,19 +801,12 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 			_log.warning(qn+".saveMember()->"+e.getMessage());
 			e.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void clearTables()
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			PreparedStatement stat1 = con.prepareStatement(SQL_CLEAR_CLAN);
 			stat1.setInt(1, _hall.getId());
 			stat1.execute();
@@ -856,11 +820,6 @@ public abstract class FlagWar extends ClanHallSiegeEngine
 		catch(Exception e)
 		{
 			_log.warning(qn+".clearTables()->"+e.getMessage());
-			e.printStackTrace();
-		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
 		}
 	}
 	

+ 4 - 30
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminBan.java

@@ -290,7 +290,6 @@ public class AdminBan implements IAdminCommandHandler
 	
 	private void banChatOfflinePlayer(L2PcInstance activeChar, String name, int delay, boolean ban)
 	{
-		Connection con = null;
 		int level = 0;
 		long value = 0;
 		if(ban)
@@ -304,10 +303,8 @@ public class AdminBan implements IAdminCommandHandler
 			value = 0;
 		}
 		
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			PreparedStatement statement = con.prepareStatement("UPDATE characters SET punish_level=?, punish_timer=? WHERE char_name=?");
 			statement.setInt(1, level);
 			statement.setLong(2, value);
@@ -331,19 +328,12 @@ public class AdminBan implements IAdminCommandHandler
 			if (Config.DEBUG)
 				se.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void jailOfflinePlayer(L2PcInstance activeChar, String name, int delay)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
 			statement.setInt(1, -114356);
 			statement.setInt(2, -249645);
@@ -367,18 +357,12 @@ public class AdminBan implements IAdminCommandHandler
 			if (Config.DEBUG)
 				se.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void unjailOfflinePlayer(L2PcInstance activeChar, String name)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
 			statement.setInt(1, 17836);
 			statement.setInt(2, 170178);
@@ -400,10 +384,6 @@ public class AdminBan implements IAdminCommandHandler
 			if (Config.DEBUG)
 				se.printStackTrace();
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private boolean changeCharAccessLevel(L2PcInstance targetPlayer, String player, L2PcInstance activeChar, int lvl)
@@ -418,10 +398,8 @@ public class AdminBan implements IAdminCommandHandler
 		}
 		else
 		{
-			Connection con = null;
-			try
+			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 			{
-				con = L2DatabaseFactory.getInstance().getConnection();
 				PreparedStatement statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?");
 				statement.setInt(1, lvl);
 				statement.setString(2, player);
@@ -442,10 +420,6 @@ public class AdminBan implements IAdminCommandHandler
 					se.printStackTrace();
 				return false;
 			}
-			finally
-			{
-				L2DatabaseFactory.close(con);
-			}
 		}
 		return true;
 	}

+ 1 - 7
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminChangeAccessLevel.java

@@ -90,10 +90,8 @@ public class AdminChangeAccessLevel implements IAdminCommandHandler
 				onLineChange(activeChar, player, lvl);
 			else
 			{
-				Connection con = null;
-				try
+				try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 				{
-					con = L2DatabaseFactory.getInstance().getConnection();
 					PreparedStatement statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?");
 					statement.setInt(1, lvl);
 					statement.setString(2, name);
@@ -111,10 +109,6 @@ public class AdminChangeAccessLevel implements IAdminCommandHandler
 					if (Config.DEBUG)
 						se.printStackTrace();
 				}
-				finally
-				{
-					L2DatabaseFactory.close(con);
-				}
 			}
 		}
 	}

+ 1 - 7
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminClan.java

@@ -180,10 +180,8 @@ public class AdminClan implements IAdminCommandHandler
 				}
 				else if (clan.getLeaderId() > 0)
 				{
-					Connection con = null;
-					try
+					try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 					{
-						con = L2DatabaseFactory.getInstance().getConnection();
 						PreparedStatement statement = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?");
 						statement.setInt(1, L2Clan.CP_NOTHING);
 						statement.setInt(2, clan.getLeaderId());
@@ -199,10 +197,6 @@ public class AdminClan implements IAdminCommandHandler
 					{
 						activeChar.sendPacket(SystemMessageId.NOT_WORKING_PLEASE_TRY_AGAIN_LATER);
 					}
-					finally
-					{
-						L2DatabaseFactory.close(con);
-					}
 				}
 				
 				clan.setLeader(member);

+ 12 - 95
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminEditNpc.java

@@ -628,11 +628,8 @@ public class AdminEditNpc implements IAdminCommandHandler
 	
 	private boolean storeTradeList(int itemID, long price, int tradeListID, int order)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			String table = "merchant_buylists";
 			if (Config.CUSTOM_MERCHANT_TABLES)
 				table = "custom_merchant_buylists";
@@ -650,20 +647,13 @@ public class AdminEditNpc implements IAdminCommandHandler
 			_log.warning("Could not store trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
 			return false;
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 		return true;
 	}
 	
 	private void updateTradeList(int itemID, long price, int tradeListID, int order)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			int updated = 0;
 			if (Config.CUSTOM_MERCHANT_TABLES)
 			{
@@ -688,19 +678,12 @@ public class AdminEditNpc implements IAdminCommandHandler
 		{
 			_log.warning("Could not update trade list (" + itemID + ", " + price + ", " + tradeListID + ", " + order + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void deleteTradeList(int tradeListID, int order)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			int updated = 0;
 			if (Config.CUSTOM_MERCHANT_TABLES)
 			{
@@ -723,19 +706,13 @@ public class AdminEditNpc implements IAdminCommandHandler
 		{
 			_log.warning("Could not delete trade list (" + tradeListID + ", " + order + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private int findOrderTradeList(int itemID, long price, int tradeListID)
 	{
-		Connection con = null;
 		int order = -1;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement stmt = con.prepareStatement("SELECT `order` FROM `merchant_buylists` WHERE `shop_id` = ? AND `item_id` = ? AND `price` = ?");
 			stmt.setInt(1, tradeListID);
 			stmt.setInt(2, itemID);
@@ -752,10 +729,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 		{
 			_log.warning("Could not get order for (" + itemID + ", " + price + ", " + tradeListID + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 		return order;
 	}
 	
@@ -1157,12 +1130,8 @@ public class AdminEditNpc implements IAdminCommandHandler
 	
 	private void updateDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
 	{
-		Connection con = null;
-		
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			int updated = 0;
 			if (Config.CUSTOM_DROPLIST_TABLE)
 			{
@@ -1201,20 +1170,12 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not update drop data!");
 			_log.warning("Error while updating drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void addDropData(L2PcInstance activeChar, int npcId, int itemId, int min, int max, int category, int chance)
 	{
-		Connection con = null;
-		
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			String table = "droplist";
 			if (Config.CUSTOM_DROPLIST_TABLE)
 				table = "custom_droplist";
@@ -1239,10 +1200,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not add drop data!");
 			_log.warning("Error while adding drop data (" + npcId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void deleteDropData(L2PcInstance activeChar, int npcId, int itemId, int category, boolean confirmed)
@@ -1274,11 +1231,8 @@ public class AdminEditNpc implements IAdminCommandHandler
 			return;
 		}
 		
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			int updated = 0;
 			if (Config.CUSTOM_DROPLIST_TABLE)
 			{
@@ -1309,10 +1263,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not delete drop data!");
 			_log.warning("Error while deleting drop data (" + npcId + ", " + itemId + ", " + category + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void reloadNpcDropList(int npcId)
@@ -1325,11 +1275,8 @@ public class AdminEditNpc implements IAdminCommandHandler
 		npcData.clearAllDropData();
 		
 		// get the drops
-		Connection con = null;
-		
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			L2DropData dropData = null;
 			
 			PreparedStatement statement = con.prepareStatement("SELECT `mobId`, `itemId`, `min`, `max`, `category`, `chance` FROM `droplist` WHERE `mobId`=?");
@@ -1377,10 +1324,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 		{
 			_log.warning("Error while reloading npc droplist (" + npcId + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void showNpcSkillList(L2PcInstance activeChar, int npcId, int page)
@@ -1535,8 +1478,7 @@ public class AdminEditNpc implements IAdminCommandHandler
 	
 	private void updateNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
 			L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
 			if (skillData == null)
@@ -1553,7 +1495,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 				return;
 			}
 			
-			con = L2DatabaseFactory.getInstance().getConnection();
 			int updated = 0;
 			if(Config.CUSTOM_NPC_SKILLS_TABLE)
 			{
@@ -1585,10 +1526,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not update npc skill!");
 			_log.warning("Error while updating npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void showNpcSkillAdd(L2PcInstance activeChar, int npcId)
@@ -1612,8 +1549,7 @@ public class AdminEditNpc implements IAdminCommandHandler
 	
 	private void addNpcSkillData(L2PcInstance activeChar, int npcId, int skillId, int level)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
 			// skill check
 			L2Skill skillData = SkillTable.getInstance().getInfo(skillId, level);
@@ -1624,8 +1560,6 @@ public class AdminEditNpc implements IAdminCommandHandler
 				return;
 			}
 			
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			if (Config.CUSTOM_NPC_SKILLS_TABLE)
 			{
 				PreparedStatement statement = con.prepareStatement("INSERT INTO `custom_npcskills`(`npcid`, `skillid`, `level`) VALUES(?,?,?)");
@@ -1655,19 +1589,12 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not add npc skill!");
 			_log.warning("Error while adding a npc skill (" + npcId + ", " + skillId + ", " + level + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void deleteNpcSkillData(L2PcInstance activeChar, int npcId, int skillId)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
-			
 			if (npcId > 0)
 			{
 				int updated = 0;
@@ -1699,18 +1626,12 @@ public class AdminEditNpc implements IAdminCommandHandler
 			activeChar.sendMessage("Could not delete npc skill!");
 			_log.warning("Error while deleting npc skill (" + npcId + ", " + skillId + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void reloadNpcSkillList(int npcId)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			L2NpcTemplate npcData = NpcTable.getInstance().getTemplate(npcId);
 			
 			L2Skill skillData = null;
@@ -1755,9 +1676,5 @@ public class AdminEditNpc implements IAdminCommandHandler
 		{
 			_log.warning("Error while reloading npc skill list (" + npcId + "): " + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 }

+ 1 - 7
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminRepairChar.java

@@ -61,10 +61,8 @@ public class AdminRepairChar implements IAdminCommandHandler
 		}
 		
 		String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement(cmd);
 			statement.setString(1, parts[1]);
 			statement.execute();
@@ -104,9 +102,5 @@ public class AdminRepairChar implements IAdminCommandHandler
 		{
 			_log.log(Level.WARNING, "could not repair char:", e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 }

+ 1 - 12
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminShowQuests.java

@@ -146,8 +146,7 @@ public class AdminShowQuests implements IAdminCommandHandler
 	
 	private void showquestmenu(L2PcInstance target, L2PcInstance actor, String[] val)
 	{
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
 			ResultSet rs;
 			PreparedStatement req;
@@ -155,7 +154,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 			
 			TextBuilder replyMSG = new TextBuilder("<html><body>");
 			NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
-			con = L2DatabaseFactory.getInstance().getConnection();
 			
 			if (val[0].equals("full"))
 			{
@@ -165,7 +163,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 				rs = req.getResultSet();
 				while(rs.next()) replyMSG.append("<tr><td><a action=\"bypass -h admin_charquestmenu " + target.getName() + " " + rs.getString(1) + "\">"+rs.getString(1)+"</a></td></tr>");
 				replyMSG.append("</table></body></html>");
-				L2DatabaseFactory.close(con);
 			}
 			else if (val[0].equals("name"))
 			{
@@ -189,7 +186,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 				replyMSG.append("<td><button value=\"Quest Complete\" action=\"bypass -h admin_setcharquest "+target.getName()+" "+val[1]+" state COMLETED 0\" width=120 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
 				replyMSG.append("</table><br><br><font color=\"ff0000\">Delete Quest from DB:</font><br><button value=\"Quest Delete\" action=\"bypass -h admin_setcharquest "+target.getName()+" "+val[1]+" state DELETE\" width=120 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
 				replyMSG.append("</center></body></html>");
-				L2DatabaseFactory.close(con);
 			}
 			else if (val[0].equals("var"))
 			{
@@ -200,7 +196,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 				rs = req.getResultSet();
 				while(rs.next()) replyMSG.append("<tr><td><a action=\"bypass -h admin_charquestmenu " + target.getName() + " " + rs.getString(1) + "\">" + rs.getString(1)+"</a></td></tr>");
 				replyMSG.append("</table></body></html>");
-				L2DatabaseFactory.close(con);
 			}
 			else if (val[0].equals("custom"))
 			{
@@ -252,7 +247,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 						replyMSG.append("<td><button value=\"Quest Complete\" action=\"bypass -h admin_setcharquest "+target.getName()+" "+qname+" state COMLETED 0\" width=100 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
 						replyMSG.append("</table><br><br><font color=\"ff0000\">Delete Quest from DB:</font><br><button value=\"Quest Delete\" action=\"bypass -h admin_setcharquest "+target.getName()+" "+qname+" state DELETE\" width=100 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
 						replyMSG.append("</center></body></html>");
-						L2DatabaseFactory.close(con);
 					}
 					else
 					{
@@ -275,11 +269,6 @@ public class AdminShowQuests implements IAdminCommandHandler
 		catch (Exception e)
 		{
 			actor.sendMessage("Error!");
-			//e.printStackTrace();
-		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
 		}
 	}
 	

+ 1 - 7
L2J_DataPack_BETA/dist/game/data/scripts/handlers/admincommandhandlers/AdminTeleport.java

@@ -503,13 +503,11 @@ public class AdminTeleport implements IAdminCommandHandler
 	
 	private void changeCharacterPosition(L2PcInstance activeChar, String name)
 	{
-		Connection con = null;
 		final int x = activeChar.getX();
 		final int y = activeChar.getY();
 		final int z = activeChar.getZ();
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
 			statement.setInt(1, x);
 			statement.setInt(2, y);
@@ -527,10 +525,6 @@ public class AdminTeleport implements IAdminCommandHandler
 		{
 			activeChar.sendMessage("SQLException while changing offline character's position");
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 	}
 	
 	private void recallNPC(L2PcInstance activeChar)

+ 2 - 16
L2J_DataPack_BETA/dist/game/data/scripts/handlers/telnethandlers/PlayerHandler.java

@@ -215,11 +215,8 @@ public class PlayerHandler implements ITelnetHandler
 				}
 				else
 				{
-					Connection con = null;
-					try
+					try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 					{
-						con = L2DatabaseFactory.getInstance().getConnection();
-						
 						PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
 						statement.setInt(1, -114356);
 						statement.setInt(2, -249645);
@@ -243,10 +240,6 @@ public class PlayerHandler implements ITelnetHandler
 						if (Config.DEBUG)
 							se.printStackTrace();
 					}
-					finally
-					{
-						L2DatabaseFactory.close(con);
-					}
 				}
 			}
 			catch (NoSuchElementException nsee)
@@ -274,11 +267,8 @@ public class PlayerHandler implements ITelnetHandler
 				}
 				else
 				{
-					Connection con = null;
-					try
+					try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 					{
-						con = L2DatabaseFactory.getInstance().getConnection();
-						
 						PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
 						statement.setInt(1, 17836);
 						statement.setInt(2, 170178);
@@ -302,10 +292,6 @@ public class PlayerHandler implements ITelnetHandler
 						if (Config.DEBUG)
 							se.printStackTrace();
 					}
-					finally
-					{
-						L2DatabaseFactory.close(con);
-					}
 				}
 			}
 			catch (NoSuchElementException nsee)

+ 2 - 8
L2J_DataPack_BETA/dist/game/data/scripts/handlers/usercommandhandlers/ClanWarsList.java

@@ -14,6 +14,7 @@
  */
 package handlers.usercommandhandlers;
 
+import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.util.logging.Level;
@@ -53,11 +54,8 @@ public class ClanWarsList implements IUserCommandHandler
 		}
 		
 		SystemMessage sm;
-		java.sql.Connection con = null;
-		
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			PreparedStatement statement;
 			
 			if (id == 88)
@@ -119,10 +117,6 @@ public class ClanWarsList implements IUserCommandHandler
 		{
 			_log.log(Level.WARNING, "", e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 		
 		return true;
 	}

+ 1 - 7
L2J_DataPack_BETA/dist/game/data/scripts/handlers/voicedcommandhandlers/Wedding.java

@@ -211,10 +211,8 @@ public class Wedding implements IVoicedCommandHandler
 		// check if target has player on friendlist
 		boolean FoundOnFriendList = false;
 		int objectId;
-		Connection con = null;
-		try
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
 		{
-			con = L2DatabaseFactory.getInstance().getConnection();
 			final PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?");
 			statement.setInt(1, ptarget.getObjectId());
 			final ResultSet rset = statement.executeQuery();
@@ -232,10 +230,6 @@ public class Wedding implements IVoicedCommandHandler
 		{
 			_log.warning("could not read friend data:" + e);
 		}
-		finally
-		{
-			L2DatabaseFactory.close(con);
-		}
 		
 		if (!FoundOnFriendList)
 		{