Fix autoclosing on resultsets

This commit is contained in:
Paul Reilly 2023-03-30 22:46:45 -05:00
parent c26e05c392
commit 74408b85bf

View File

@ -127,18 +127,12 @@ public class SQLite extends FreedomService
public ResultSet getBanList() throws SQLException public ResultSet getBanList() throws SQLException
{ {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM bans")) return connection.prepareStatement("SELECT * FROM bans").executeQuery();
{
return statement.executeQuery();
}
} }
public ResultSet getAdminList() throws SQLException public ResultSet getAdminList() throws SQLException
{ {
try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM admins")) return connection.prepareStatement("SELECT * FROM admins").executeQuery();
{
return statement.executeQuery();
}
} }
public void setAdminValue(Admin admin, String key, Object value) public void setAdminValue(Admin admin, String key, Object value)
@ -264,8 +258,11 @@ public class SQLite extends FreedomService
public ResultSet getAdminByUuid(UUID uuid) public ResultSet getAdminByUuid(UUID uuid)
{ {
try (ResultSet resultSet = connection.createStatement().executeQuery(MessageFormat.format("SELECT * FROM admins WHERE uuid=''{0}''", uuid.toString()))) try
{ {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM admins WHERE uuid=?");
statement.setString(1, uuid.toString());
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) if (resultSet.next())
{ {
return resultSet; return resultSet;
@ -281,8 +278,12 @@ public class SQLite extends FreedomService
public ResultSet getPlayerByUuid(UUID uuid) public ResultSet getPlayerByUuid(UUID uuid)
{ {
try (ResultSet resultSet = connection.createStatement().executeQuery(MessageFormat.format("SELECT * FROM players WHERE uuid=''{0}''", uuid.toString()))) try
{ {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM players WHERE uuid=?");
statement.setString(1, uuid.toString());
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) if (resultSet.next())
{ {
return resultSet; return resultSet;
@ -298,9 +299,9 @@ public class SQLite extends FreedomService
public ResultSet getMasterBuilders() public ResultSet getMasterBuilders()
{ {
try (ResultSet resultSet = connection.createStatement().executeQuery("SELECT * FROM players WHERE master_builder=true")) try
{ {
return resultSet; return connection.prepareStatement("SELECT * FROM players WHERE master_builder=true").executeQuery();
} catch (SQLException e) } catch (SQLException e)
{ {
FLog.severe("Failed to get Master Builders:"); FLog.severe("Failed to get Master Builders:");
@ -312,8 +313,11 @@ public class SQLite extends FreedomService
public ResultSet getPlayerByIp(String ip) public ResultSet getPlayerByIp(String ip)
{ {
try (ResultSet resultSet = connection.createStatement().executeQuery(MessageFormat.format("SELECT * FROM players WHERE ips LIKE ''%{0}%''", ip))) try
{ {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM players WHERE ips LIKE %?%");
statement.setString(1, ip);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) if (resultSet.next())
{ {
return resultSet; return resultSet;