Added AntiHack to Arcade/Hub

Added AntiHack Offense uploading.
Fixed memory leaks in PreparedStatments
Added Ultra tag in hub chat.
This commit is contained in:
Jonathan Williams 2013-10-17 00:37:57 -07:00
parent d23f72567a
commit f88c202e07
12 changed files with 357 additions and 36 deletions

View File

@ -16,13 +16,14 @@ public class GlobalServerRepository
public void initialize() public void initialize()
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
} }
catch (Exception exception) catch (Exception exception)
@ -31,6 +32,18 @@ public class GlobalServerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try

View File

@ -20,13 +20,14 @@ public class LobbyBalancerRepository
public void initialize() public void initialize()
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
} }
catch (Exception exception) catch (Exception exception)
@ -35,6 +36,18 @@ public class LobbyBalancerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -53,13 +66,14 @@ public class LobbyBalancerRepository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES); preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -84,6 +98,18 @@ public class LobbyBalancerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try

View File

@ -33,18 +33,21 @@ public class PlayerCountRepository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
// Retrieve id // Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID); preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address); preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery(); resultSet = preparedStatementRetrieve.executeQuery();
@ -56,7 +59,7 @@ public class PlayerCountRepository
// Insert if not there // Insert if not there
if (_id == -1) if (_id == -1)
{ {
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS); preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _address); preparedStatementInsert.setString(1, _address);
preparedStatementInsert.setInt(2, 0); preparedStatementInsert.setInt(2, 0);
@ -86,6 +89,42 @@ public class PlayerCountRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementRetrieve != null)
{
try
{
preparedStatementRetrieve.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementInsert != null)
{
try
{
preparedStatementInsert.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try
@ -115,12 +154,13 @@ public class PlayerCountRepository
public boolean updatePlayerCountInDatabase(int players) public boolean updatePlayerCountInDatabase(int players)
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS); preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, players); preparedStatement.setInt(1, players);
preparedStatement.setInt(2, _maxPlayers); preparedStatement.setInt(2, _maxPlayers);
@ -144,6 +184,18 @@ public class PlayerCountRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -163,12 +215,13 @@ public class PlayerCountRepository
Connection connection = null; Connection connection = null;
PlayerTotalData playerData = new PlayerTotalData(); PlayerTotalData playerData = new PlayerTotalData();
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT); preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -184,6 +237,18 @@ public class PlayerCountRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try

View File

@ -21,13 +21,14 @@ public class PlayerTrackerRepository
public void initialize() public void initialize()
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
} }
catch (Exception exception) catch (Exception exception)
@ -36,6 +37,18 @@ public class PlayerTrackerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -53,12 +66,13 @@ public class PlayerTrackerRepository
public boolean updatePlayerServer(String name, String server) public boolean updatePlayerServer(String name, String server)
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER); preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER);
preparedStatement.setString(1, server); preparedStatement.setString(1, server);
preparedStatement.setString(2, name); preparedStatement.setString(2, name);
@ -89,6 +103,18 @@ public class PlayerTrackerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -107,12 +133,13 @@ public class PlayerTrackerRepository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER); preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER);
preparedStatement.setString(1, name); preparedStatement.setString(1, name);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
@ -127,6 +154,18 @@ public class PlayerTrackerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try
@ -158,12 +197,13 @@ public class PlayerTrackerRepository
public boolean removePlayer(String name) public boolean removePlayer(String name)
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(DELETE_PLAYER); preparedStatement = connection.prepareStatement(DELETE_PLAYER);
preparedStatement.setString(1, name); preparedStatement.setString(1, name);
@ -183,6 +223,18 @@ public class PlayerTrackerRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try

View File

@ -30,6 +30,9 @@ import org.bukkit.util.Vector;
public class AntiHack extends MiniPlugin public class AntiHack extends MiniPlugin
{ {
public static AntiHack Instance; public static AntiHack Instance;
private static Object _offensesSynch = new Object();
private AntiHackRepository _repository;
//Record Offesnes //Record Offesnes
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>(); private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
@ -58,6 +61,9 @@ public class AntiHack extends MiniPlugin
protected AntiHack(JavaPlugin plugin) protected AntiHack(JavaPlugin plugin)
{ {
super("AntiHack", plugin); super("AntiHack", plugin);
_repository = new AntiHackRepository(this, plugin.getConfig().getString("serverstatus.name"));
_repository.initialize();
} }
public static void Initialize(JavaPlugin plugin) public static void Initialize(JavaPlugin plugin)
@ -135,7 +141,8 @@ public class AntiHack extends MiniPlugin
if (!UtilTime.elapsed(_lastMove.get(player), _freecamTime)) if (!UtilTime.elapsed(_lastMove.get(player), _freecamTime))
continue; continue;
player.kickPlayer(C.cGold + "Mineplex " + C.cRed + "Anti-Hack " + C.cWhite + "Kicked for Lagging / Free Cam."); //player.kickPlayer(C.cGold + "Mineplex " + C.cRed + "Anti-Hack " + C.cWhite + "Kicked for Lagging / Free Cam.");
AddOffense(player, "Free Cam / Lag / Float");
} }
} }
@ -162,6 +169,25 @@ public class AntiHack extends MiniPlugin
UpdateSpeed(player, event); UpdateSpeed(player, event);
} }
public HashMap<Player, HashMap<String, Integer>> getOffenses()
{
return _offenses;
}
public Object getOffensesSynch()
{
return _offensesSynch;
}
@EventHandler
public void updateDatabase(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
return;
_repository.saveOffenses();
}
private void UpdateFloat(Player player) private void UpdateFloat(Player player)
{ {
int count = 0; int count = 0;
@ -276,6 +302,7 @@ public class AntiHack extends MiniPlugin
limit = 0.32; limit = 0.32;
for (PotionEffect effect : player.getActivePotionEffects()) for (PotionEffect effect : player.getActivePotionEffects())
{
if (effect.getType().equals(PotionEffectType.SPEED)) if (effect.getType().equals(PotionEffectType.SPEED))
{ {
if (UtilEnt.isGrounded(player)) if (UtilEnt.isGrounded(player))
@ -283,6 +310,7 @@ public class AntiHack extends MiniPlugin
else else
limit += 0.04 * (effect.getAmplifier() + 1); limit += 0.04 * (effect.getAmplifier() + 1);
} }
}
//Check //Check
if (offset > limit && !UtilTime.elapsed(_speedTicks.get(player).getValue(), 200))//Counters Lag if (offset > limit && !UtilTime.elapsed(_speedTicks.get(player).getValue(), 200))//Counters Lag
@ -305,6 +333,8 @@ public class AntiHack extends MiniPlugin
} }
private void AddOffense(Player player, String type) private void AddOffense(Player player, String type)
{
synchronized (getOffensesSynch())
{ {
if (!_offenses.containsKey(player)) if (!_offenses.containsKey(player))
_offenses.put(player, new HashMap<String, Integer>()); _offenses.put(player, new HashMap<String, Integer>());
@ -314,6 +344,7 @@ public class AntiHack extends MiniPlugin
previous = _offenses.get(player).get(type); previous = _offenses.get(player).get(type);
_offenses.get(player).put(type, previous + 1); _offenses.get(player).put(type, previous + 1);
}
//Print (Debug) //Print (Debug)
System.out.println("[Offense] " + player.getName() + " received offense for " + type + "."); System.out.println("[Offense] " + player.getName() + " received offense for " + type + ".");
@ -337,6 +368,10 @@ public class AntiHack extends MiniPlugin
_ignore.remove(player); _ignore.remove(player);
_ignoreStart.remove(player); _ignoreStart.remove(player);
synchronized (getOffensesSynch())
{
_offenses.remove(player); _offenses.remove(player);
} }
}
} }

View File

@ -42,18 +42,21 @@ public class ServerStatusRepository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
// Retrieve id // Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID); preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address); preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery(); resultSet = preparedStatementRetrieve.executeQuery();
@ -65,7 +68,7 @@ public class ServerStatusRepository
// Insert if not there // Insert if not there
if (_id == -1) if (_id == -1)
{ {
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS); preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _serverName); preparedStatementInsert.setString(1, _serverName);
preparedStatementInsert.setString(2, _serverGroup); preparedStatementInsert.setString(2, _serverGroup);
@ -99,6 +102,42 @@ public class ServerStatusRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementRetrieve != null)
{
try
{
preparedStatementRetrieve.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementInsert != null)
{
try
{
preparedStatementInsert.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try
@ -128,12 +167,13 @@ public class ServerStatusRepository
public boolean updatePlayerCountInDatabase(String motd, int players, int maxPlayers, int tps) public boolean updatePlayerCountInDatabase(String motd, int players, int maxPlayers, int tps)
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS); preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, _serverName); preparedStatement.setString(1, _serverName);
preparedStatement.setString(2, _serverGroup); preparedStatement.setString(2, _serverGroup);
@ -161,6 +201,18 @@ public class ServerStatusRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -179,13 +231,14 @@ public class ServerStatusRepository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES); preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -206,6 +259,18 @@ public class ServerStatusRepository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try

View File

@ -2,6 +2,7 @@ package mineplex.hub;
import me.chiss.Core.MemoryFix.MemoryFix; import me.chiss.Core.MemoryFix.MemoryFix;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter; import mineplex.core.command.CommandCenter;
@ -66,6 +67,7 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
CommandCenter.Initialize(this, clientManager); CommandCenter.Initialize(this, clientManager);
ItemStackFactory.Initialize(this, false); ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this); Recharge.Initialize(this);
AntiHack.Initialize(this);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress()); DonationManager donationManager = new DonationManager(this, GetWebServerAddress());

View File

@ -319,9 +319,15 @@ public class HubManager extends MiniClientPlugin<HubClient>
Rank rank = GetClients().Get(player).GetRank(); Rank rank = GetClients().Get(player).GetRank();
boolean ownsUltra = _donationManager.Get(player.getName()).OwnsUltraPackage();
//Rank Prefix
String rankStr = ""; String rankStr = "";
if (rank != Rank.ALL) if (rank != Rank.ALL)
rankStr = rank.Color + C.Bold + GetClients().Get(player).GetRank().Name.toUpperCase() + " "; rankStr = rank.Color + C.Bold + rank.Name.toUpperCase() + " ";
if (ownsUltra && !rank.Has(Rank.ULTRA))
rankStr = Rank.ULTRA.Color + C.Bold + Rank.ULTRA.Name.toUpperCase() + " ";
//Party Chat //Party Chat
if (event.getMessage().charAt(0) == '@') if (event.getMessage().charAt(0) == '@')

View File

@ -0,0 +1,6 @@
package mineplex.servermonitor;
public class DynamicMonitor
{
}

View File

@ -0,0 +1,13 @@
package mineplex.servermonitor;
import java.util.ArrayList;
import java.util.List;
public class GroupStatusData
{
public String Name;
public int Players;
public int MaxPlayers;
public List<ServerStatusData> Servers = new ArrayList<ServerStatusData>();
}

View File

@ -20,8 +20,8 @@ public class Repository
public void initialize() public void initialize()
{ {
Connection connection = null; Connection connection = null;
PreparedStatement preparedStatement = null;
try try
{ {
@ -30,7 +30,7 @@ public class Repository
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table // Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE); preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute(); preparedStatement.execute();
} }
catch (Exception exception) catch (Exception exception)
@ -39,6 +39,18 @@ public class Repository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null) if (connection != null)
{ {
try try
@ -57,13 +69,14 @@ public class Repository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>(); List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES); preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -88,6 +101,18 @@ public class Repository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try
@ -120,13 +145,14 @@ public class Repository
{ {
Connection connection = null; Connection connection = null;
ResultSet resultSet = null; ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<GroupStatusData> groupData = new ArrayList<GroupStatusData>(); List<GroupStatusData> groupData = new ArrayList<GroupStatusData>();
try try
{ {
connection = DriverManager.getConnection(_connectionString, _userName, _password); connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES); preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery(); resultSet = preparedStatement.executeQuery();
while (resultSet.next()) while (resultSet.next())
@ -151,6 +177,18 @@ public class Repository
} }
finally finally
{ {
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null) if (resultSet != null)
{ {
try try