Преглед на файлове

PreparedStatement used as batch o_O

janiii преди 15 години
родител
ревизия
2beeaf47d3

+ 1 - 2
L2_GameServer/java/com/l2jserver/L2DatabaseFactory.java

@@ -250,8 +250,7 @@ public class L2DatabaseFactory
 			{
 				if (!c.isClosed())
 				{
-					_log.warning("Unclosed connection! Trace:");
-					exp.printStackTrace();
+					_log.log(Level.WARNING, "Unclosed connection! Trace: " + exp.getStackTrace()[1], exp);
 				}
 			}
 			catch (SQLException e)

+ 1 - 1
L2_GameServer/java/com/l2jserver/gameserver/datatables/UITable.java

@@ -36,7 +36,7 @@ import com.l2jserver.gameserver.model.entity.ActionKey;
  */
 public class UITable
 {
-	private static Logger _log = Logger.getLogger(StaticObjects.class.getName());
+	private static Logger _log = Logger.getLogger(UITable.class.getName());
 	
 	private Map<Integer, List<ActionKey>> _storedKeys;
 	private Map<Integer, List<Integer>> _storedCategories;

+ 11 - 9
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/CastleManorManager.java

@@ -206,11 +206,12 @@ public class CastleManorManager
 	{
 		Connection con = null;
 		ResultSet rs;
-		PreparedStatement statement;
 		try
 		{
 			// Get Connection
 			con = L2DatabaseFactory.getInstance().getConnection();
+			PreparedStatement statementProduction = con.prepareStatement(CASTLE_MANOR_LOAD_PRODUCTION);
+			PreparedStatement statementProcure = con.prepareStatement(CASTLE_MANOR_LOAD_PROCURE);
 			for (Castle castle : CastleManager.getInstance().getCastles())
 			{
 				FastList<SeedProduction> production = new FastList<SeedProduction>();
@@ -219,9 +220,9 @@ public class CastleManorManager
 				FastList<CropProcure> procureNext = new FastList<CropProcure>();
 
 				// restore seed production info
-				statement = con.prepareStatement(CASTLE_MANOR_LOAD_PRODUCTION);
-				statement.setInt(1, castle.getCastleId());
-				rs = statement.executeQuery();
+				statementProduction.setInt(1, castle.getCastleId());
+				rs = statementProduction.executeQuery();
+				statementProduction.clearParameters();
 				while (rs.next())
 				{
 					int seedId = rs.getInt("seed_id");
@@ -235,15 +236,15 @@ public class CastleManorManager
 						productionNext.add(new SeedProduction(seedId, canProduce, price, startProduce));
 				}
 				rs.close();
-				statement.close();
 
 				castle.setSeedProduction(production, PERIOD_CURRENT);
 				castle.setSeedProduction(productionNext, PERIOD_NEXT);
 
 				// restore procure info
-				statement = con.prepareStatement(CASTLE_MANOR_LOAD_PROCURE);
-				statement.setInt(1, castle.getCastleId());
-				rs = statement.executeQuery();
+				
+				statementProcure.setInt(1, castle.getCastleId());
+				rs = statementProcure.executeQuery();
+				statementProcure.clearParameters();
 				while (rs.next())
 				{
 					int cropId = rs.getInt("crop_id");
@@ -258,7 +259,6 @@ public class CastleManorManager
 						procureNext.add(new CropProcure(cropId, canBuy, rewardType, startBuy, price));
 				}
 				rs.close();
-				statement.close();
 
 				castle.setCropProcure(procure, PERIOD_CURRENT);
 				castle.setCropProcure(procureNext, PERIOD_NEXT);
@@ -266,6 +266,8 @@ public class CastleManorManager
 				if (!procure.isEmpty() || !procureNext.isEmpty() || !production.isEmpty() || !productionNext.isEmpty())
 					_log.info(castle.getName() + ": Data loaded");
 			}
+			statementProduction.close();
+			statementProcure.close();
 		}
 		catch (Exception e)
 		{

+ 24 - 16
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/FourSepulchersManager.java

@@ -527,14 +527,16 @@ public class FourSepulchersManager
 			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())
 			{
 				int keyNpcId = rset1.getInt("key_npc_id");
 				
-				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");
 				statement2.setInt(1, keyNpcId);
 				statement2.setInt(2, 1);
 				ResultSet rset2 = statement2.executeQuery();
+				statement2.clearParameters();
 				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
@@ -559,18 +561,18 @@ public class FourSepulchersManager
 					}
 					else
 					{
-						_log.warning("FourSepulchersManager.LoadPhysicalMonsters: Data missing in NPC table for ID: "
-								+ rset2.getInt("npc_templateid") + ".");
+						_log.warning("FourSepulchersManager.LoadPhysicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
 					}
 				}
 				
 				rset2.close();
-				statement2.close();
 				_physicalMonsters.put(keyNpcId, _physicalSpawns);
 			}
 			
 			rset1.close();
 			statement1.close();
+			statement2.close();
+			
 			_log.info("FourSepulchersManager: loaded " + loaded + " Physical type monsters spawns.");
 		}
 		catch (Exception e)
@@ -605,14 +607,16 @@ public class FourSepulchersManager
 			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())
 			{
 				int keyNpcId = rset1.getInt("key_npc_id");
 				
-				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");
 				statement2.setInt(1, keyNpcId);
 				statement2.setInt(2, 2);
 				ResultSet rset2 = statement2.executeQuery();
+				statement2.clearParameters();
 				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
@@ -637,18 +641,18 @@ public class FourSepulchersManager
 					}
 					else
 					{
-						_log.warning("FourSepulchersManager.LoadMagicalMonsters: Data missing in NPC table for ID: "
-								+ rset2.getInt("npc_templateid") + ".");
+						_log.warning("FourSepulchersManager.LoadMagicalMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
 					}
 				}
 				
 				rset2.close();
-				statement2.close();
 				_magicalMonsters.put(keyNpcId, _magicalSpawns);
 			}
 			
 			rset1.close();
 			statement1.close();
+			statement2.close();
+			
 			_log.info("FourSepulchersManager: loaded " + loaded + " Magical type monsters spawns.");
 		}
 		catch (Exception e)
@@ -683,14 +687,16 @@ public class FourSepulchersManager
 			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())
 			{
 				int keyNpcId = rset1.getInt("key_npc_id");
 				
-				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");
 				statement2.setInt(1, keyNpcId);
 				statement2.setInt(2, 5);
 				ResultSet rset2 = statement2.executeQuery();
+				statement2.clearParameters();
 				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
@@ -715,19 +721,19 @@ public class FourSepulchersManager
 					}
 					else
 					{
-						_log.warning("FourSepulchersManager.LoadDukeMonsters: Data missing in NPC table for ID: "
-								+ rset2.getInt("npc_templateid") + ".");
+						_log.warning("FourSepulchersManager.LoadDukeMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
 					}
 				}
 				
 				rset2.close();
-				statement2.close();
 				_dukeFinalMobs.put(keyNpcId, _dukeFinalSpawns);
 				_archonSpawned.put(keyNpcId, false);
 			}
 			
 			rset1.close();
 			statement1.close();
+			statement2.close();
+			
 			_log.info("FourSepulchersManager: loaded " + loaded + " Church of duke monsters spawns.");
 		}
 		catch (Exception e)
@@ -762,14 +768,16 @@ public class FourSepulchersManager
 			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())
 			{
 				int keyNpcId = rset1.getInt("key_npc_id");
 				
-				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");
 				statement2.setInt(1, keyNpcId);
 				statement2.setInt(2, 6);
 				ResultSet rset2 = statement2.executeQuery();
+				statement2.clearParameters();
 				
 				L2Spawn spawnDat;
 				L2NpcTemplate template1;
@@ -794,18 +802,18 @@ public class FourSepulchersManager
 					}
 					else
 					{
-						_log.warning("FourSepulchersManager.LoadEmperorsGraveMonsters: Data missing in NPC table for ID: "
-								+ rset2.getInt("npc_templateid") + ".");
+						_log.warning("FourSepulchersManager.LoadEmperorsGraveMonsters: Data missing in NPC table for ID: " + rset2.getInt("npc_templateid") + ".");
 					}
 				}
 				
 				rset2.close();
-				statement2.close();
 				_emperorsGraveNpcs.put(keyNpcId, _emperorsGraveSpawns);
 			}
 			
 			rset1.close();
 			statement1.close();
+			statement2.close();
+			
 			_log.info("FourSepulchersManager: loaded " + loaded + " Emperor's grave NPC spawns.");
 		}
 		catch (Exception e)

+ 28 - 24
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/GrandBossManager.java

@@ -347,15 +347,15 @@ public class GrandBossManager
 	private void storeToDb()
 	{
 		Connection con = null;
-		PreparedStatement statement = null;
 		try
 		{
 			con = L2DatabaseFactory.getInstance().getConnection();
 			
-			statement = con.prepareStatement(DELETE_GRAND_BOSS_LIST);
-			statement.executeUpdate();
-			statement.close();
+			PreparedStatement deleteStatement = con.prepareStatement(DELETE_GRAND_BOSS_LIST);
+			deleteStatement.executeUpdate();
+			deleteStatement.close();
 			
+			PreparedStatement insertStatement = con.prepareStatement(INSERT_GRAND_BOSS_LIST);
 			for (L2BossZone zone : _zones)
 			{
 				if (zone == null)
@@ -366,32 +366,34 @@ public class GrandBossManager
 					continue;
 				for (Integer player : list)
 				{
-					statement = con.prepareStatement(INSERT_GRAND_BOSS_LIST);
-					statement.setInt(1, player);
-					statement.setInt(2, id);
-					statement.executeUpdate();
-					statement.close();
+					insertStatement.setInt(1, player);
+					insertStatement.setInt(2, id);
+					insertStatement.executeUpdate();
+					insertStatement.clearParameters();
 				}
 			}
+			insertStatement.close();
 			
+			PreparedStatement updateStatement1 = con.prepareStatement(UPDATE_GRAND_BOSS_DATA2);
+			PreparedStatement updateStatement2 = con.prepareStatement(UPDATE_GRAND_BOSS_DATA);
 			for (Integer bossId : _storedInfo.keys())
 			{
 				L2GrandBossInstance boss = _bosses.get(bossId);
 				StatsSet info = _storedInfo.get(bossId);
 				if (boss == null || info == null)
 				{
-					statement = con.prepareStatement(UPDATE_GRAND_BOSS_DATA2);
-					statement.setInt(1, _bossStatus.get(bossId));
-					statement.setInt(2, bossId);
+					updateStatement1.setInt(1, _bossStatus.get(bossId));
+					updateStatement1.setInt(2, bossId);
+					updateStatement1.executeUpdate();
+					updateStatement1.clearParameters();
 				}
 				else
 				{
-					statement = 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"));
+					updateStatement2.setInt(1, boss.getX());
+					updateStatement2.setInt(2, boss.getY());
+					updateStatement2.setInt(3, boss.getZ());
+					updateStatement2.setInt(4, boss.getHeading());
+					updateStatement2.setLong(5, info.getLong("respawn_time"));
 					double hp = boss.getCurrentHp();
 					double mp = boss.getCurrentMp();
 					if (boss.isDead())
@@ -399,14 +401,16 @@ 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);
+					updateStatement2.setDouble(6, hp);
+					updateStatement2.setDouble(7, mp);
+					updateStatement2.setInt(8, _bossStatus.get(bossId));
+					updateStatement2.setInt(9, bossId);
+					updateStatement2.executeUpdate();
+					updateStatement2.clearParameters();
 				}
-				statement.executeUpdate();
-				statement.close();
 			}
+			updateStatement1.close();
+			updateStatement2.close();
 		}
 		catch (SQLException e)
 		{

+ 4 - 4
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/ItemsOnGroundManager.java

@@ -244,6 +244,7 @@ public class ItemsOnGroundManager
 			try
 			{
 				con = L2DatabaseFactory.getInstance().getConnection();
+				statement = con.prepareStatement("INSERT INTO itemsonground(object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable) VALUES(?,?,?,?,?,?,?,?,?)");
 				
 				for (L2ItemInstance item : _items)
 				{
@@ -252,11 +253,9 @@ public class ItemsOnGroundManager
 					
 					if (CursedWeaponsManager.getInstance().isCursed(item.getItemId()))
 						continue; // Cursed Items not saved to ground, prevent double save
-						
 					
 					try
 					{
-						statement = con.prepareStatement("insert into itemsonground(object_id,item_id,count,enchant_level,x,y,z,drop_time,equipable) values(?,?,?,?,?,?,?,?,?)");
 						statement.setInt(1, item.getObjectId());
 						statement.setInt(2, item.getItemId());
 						statement.setLong(3, item.getCount());
@@ -274,7 +273,7 @@ public class ItemsOnGroundManager
 						else
 							statement.setLong(9, 0);
 						statement.execute();
-						statement.close();
+						statement.clearParameters();
 					}
 					catch (Exception e)
 					{
@@ -282,10 +281,11 @@ public class ItemsOnGroundManager
 						e.printStackTrace();
 					}
 				}
+				statement.close();
 			}
 			catch (SQLException e)
 			{
-				
+				e.printStackTrace();
 			}
 			finally
 			{

+ 5 - 2
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/RaidBossPointsManager.java

@@ -64,21 +64,24 @@ public class RaidBossPointsManager
 			}
 			rset.close();
 			statement.close();
+			
+			statement = con.prepareStatement("SELECT * FROM `character_raid_points` WHERE `charId`=?");
 			for(FastList.Node<Integer> n = _chars.head(), end = _chars.tail(); (n = n.getNext()) != end;)
 			{
 				int charId = n.getValue();
 				FastMap<Integer, Integer> values = new FastMap<Integer, Integer>();
-				statement = con.prepareStatement("SELECT * FROM `character_raid_points` WHERE `charId`=?");
+				
 				statement.setInt(1, charId);
 				rset = statement.executeQuery();
+				statement.clearParameters();
 				while(rset.next())
 				{
 					values.put(rset.getInt("boss_id"), rset.getInt("points"));
 				}
 				rset.close();
-				statement.close();
 				_list.put(charId, values);
 			}
+			statement.close();
 		}
 		catch (SQLException e)
 		{

+ 5 - 4
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/RaidBossSpawnManager.java

@@ -385,10 +385,11 @@ public class RaidBossSpawnManager
 	private void updateDb()
 	{
 		Connection con = null;
+		PreparedStatement statement = null;
 		try
 		{
 			con = L2DatabaseFactory.getInstance().getConnection();
-			PreparedStatement statement = null;
+			statement = con.prepareStatement("UPDATE raidboss_spawnlist SET respawn_time = ?, currentHP = ?, currentMP = ? WHERE boss_id = ?");
 			
 			for (Integer bossId : _storedInfo.keySet())
 			{
@@ -410,19 +411,19 @@ public class RaidBossSpawnManager
 				
 				try
 				{
-					statement = con.prepareStatement("UPDATE raidboss_spawnlist SET respawn_time = ?, currentHP = ?, currentMP = ? WHERE boss_id = ?");
 					statement.setLong(1, info.getLong("respawnTime"));
 					statement.setDouble(2, info.getDouble("currentHP"));
 					statement.setDouble(3, info.getDouble("currentMP"));
 					statement.setInt(4, bossId);
-					statement.execute();
-					statement.close();
+					statement.executeUpdate();
+					statement.clearParameters();
 				}
 				catch (SQLException e)
 				{
 					_log.warning("RaidBossSpawnManager: Couldnt update raidboss_spawnlist table " + e);
 				}
 			}
+			statement.close();
 		}
 		catch (SQLException e)
 		{

+ 19 - 29
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/ZoneManager.java

@@ -28,7 +28,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
-
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -53,7 +52,7 @@ public class ZoneManager
 {
 	private static final Logger _log = Logger.getLogger(ZoneManager.class.getName());
 	
-	private final FastMap<Integer, L2ZoneType> _zones = new FastMap<Integer,L2ZoneType>();
+	private final FastMap<Integer, L2ZoneType> _zones = new FastMap<Integer, L2ZoneType>();
 	
 	public static final ZoneManager getInstance()
 	{
@@ -98,6 +97,7 @@ public class ZoneManager
 	{
 		_log.info("Loading zones...");
 		Connection con = null;
+		PreparedStatement statement = null;
 		_zones.clear();
 		
 		// Get the world regions
@@ -108,6 +108,7 @@ public class ZoneManager
 		{
 			// Get a sql connection here
 			con = L2DatabaseFactory.getInstance().getConnection();
+			statement = con.prepareStatement("SELECT `x`, `y` FROM `zone_vertices` WHERE `id` = ? ORDER BY `order` ASC");
 			
 			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 			factory.setValidating(false);
@@ -202,13 +203,9 @@ public class ZoneManager
 							// Get the zone shape from sql
 							try
 							{
-								PreparedStatement statement = null;
-								
-								// Set the correct query
-								statement = con.prepareStatement("SELECT x,y FROM zone_vertices WHERE id=? ORDER BY 'order' ASC ");
-								
 								statement.setInt(1, zoneId);
 								ResultSet rset = statement.executeQuery();
+								statement.clearParameters();
 								
 								// Create this zone. Parsing for cuboids is a
 								// bit different than for other polygons
@@ -231,12 +228,11 @@ public class ZoneManager
 										else
 										{
 											_log.warning("ZoneData: Missing cuboid vertex in sql data for zone: " + zoneId);
-											rset.close();
-											statement.close();
 											successfulLoad = false;
 											break;
 										}
 									}
+									rset.close();
 									
 									if (successfulLoad)
 										temp.setZone(new ZoneCuboid(x[0], x[1], y[0], y[1], minZ, maxZ));
@@ -253,6 +249,7 @@ public class ZoneManager
 										fl_x.add(rset.getInt("x"));
 										fl_y.add(rset.getInt("y"));
 									}
+									rset.close();
 									
 									// An nPoly needs to have at least 3
 									// vertices
@@ -276,20 +273,19 @@ public class ZoneManager
 									else
 									{
 										_log.warning("ZoneData: Bad sql data for zone: " + zoneId);
-										rset.close();
-										statement.close();
 										continue;
 									}
 								}
 								else if (zoneShape.equalsIgnoreCase("Cylinder"))
 								{
-									// A Cylinder zone requires a centre point
+									// A Cylinder zone requires a center point
 									// at x,y and a radius
 									int zoneRad = Integer.parseInt(attrs.getNamedItem("rad").getNodeValue());
 									if (rset.next() && zoneRad > 0)
 									{
 										int zoneX = rset.getInt("x");
 										int zoneY = rset.getInt("y");
+										rset.close();
 										
 										// create the zone
 										temp.setZone(new ZoneCylinder(zoneX, zoneY, minZ, maxZ, zoneRad));
@@ -297,8 +293,6 @@ public class ZoneManager
 									else
 									{
 										_log.warning("ZoneData: Bad sql data for zone: " + zoneId);
-										rset.close();
-										statement.close();
 										continue;
 									}
 								}
@@ -306,19 +300,15 @@ public class ZoneManager
 								{
 									_log.warning("ZoneData: Unknown shape: " + zoneShape);
 									rset.close();
-									statement.close();
 									continue;
 								}
-								
-								rset.close();
-								statement.close();
 							}
 							catch (Exception e)
 							{
 								_log.warning("ZoneData: Failed to load zone coordinates: " + e);
 							}
 							
-							// Check for aditional parameters
+							// Check for additional parameters
 							for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
 							{
 								if ("stat".equalsIgnoreCase(cd.getNodeName()))
@@ -329,19 +319,18 @@ public class ZoneManager
 									
 									temp.setParameter(name, val);
 								}
-								else if ("spawn".equalsIgnoreCase(cd.getNodeName())
-										&& temp instanceof L2SpawnZone)
+								else if ("spawn".equalsIgnoreCase(cd.getNodeName()) && temp instanceof L2SpawnZone)
 								{
 									attrs = cd.getAttributes();
 									int spawnX = Integer.parseInt(attrs.getNamedItem("X").getNodeValue());
 									int spawnY = Integer.parseInt(attrs.getNamedItem("Y").getNodeValue());
 									int spawnZ = Integer.parseInt(attrs.getNamedItem("Z").getNodeValue());
-
+									
 									Node val = attrs.getNamedItem("isChaotic");
 									if (val != null && Boolean.parseBoolean(val.getNodeValue()))
-											((L2SpawnZone)temp).addChaoticSpawn(spawnX, spawnY, spawnZ);
+										((L2SpawnZone) temp).addChaoticSpawn(spawnX, spawnY, spawnZ);
 									else
-										((L2SpawnZone)temp).addSpawn(spawnX, spawnY, spawnZ);
+										((L2SpawnZone) temp).addSpawn(spawnX, spawnY, spawnZ);
 								}
 							}
 							addZone(zoneId, temp);
@@ -377,6 +366,7 @@ public class ZoneManager
 					}
 				}
 			}
+			statement.close();
 		}
 		catch (Exception e)
 		{
@@ -402,7 +392,7 @@ public class ZoneManager
 	 *
 	 * @param zone
 	 */
-	public void addZone(Integer id,L2ZoneType zone)
+	public void addZone(Integer id, L2ZoneType zone)
 	{
 		_zones.put(id, zone);
 	}
@@ -416,12 +406,12 @@ public class ZoneManager
 	{
 		return _zones.values();
 	}
-
-	public L2ZoneType getZoneById( int id)
+	
+	public L2ZoneType getZoneById(int id)
 	{
 		return _zones.get(id);
 	}
-
+	
 	/**
 	 * Returns all zones from where the object is located
 	 *
@@ -530,4 +520,4 @@ public class ZoneManager
 	{
 		protected static final ZoneManager _instance = new ZoneManager();
 	}
-}
+}