Browse Source

Method refactored to use try-with-resources

master
MagicBot 2 years ago
parent
commit
8bafb32e95
  1. 33
      src/engine/db/handlers/dbEffectsBaseHandler.java

33
src/engine/db/handlers/dbEffectsBaseHandler.java

@ -9,11 +9,14 @@ @@ -9,11 +9,14 @@
package engine.db.handlers;
import engine.objects.PreparedStatementShared;
import engine.gameManager.DbManager;
import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class dbEffectsBaseHandler extends dbHandlerBase {
@ -22,24 +25,24 @@ public class dbEffectsBaseHandler extends dbHandlerBase { @@ -22,24 +25,24 @@ public class dbEffectsBaseHandler extends dbHandlerBase {
}
public static ArrayList<EffectsBase> getAllEffectsBase() {
PreparedStatementShared ps = null;
ArrayList<EffectsBase> out = new ArrayList<>();
try {
ps = new PreparedStatementShared("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC");
ResultSet rs = ps.executeQuery();
ArrayList<EffectsBase> effectList = new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) {
ResultSet rs = prepareStatement.executeQuery();
while (rs.next()) {
EffectsBase toAdd = new EffectsBase(rs);
out.add(toAdd);
effectList.add(toAdd);
}
rs.close();
} catch (Exception e) {
Logger.error(e);
} finally {
ps.release();
} catch (SQLException e) {
Logger.error(e.toString());
}
//testHash(out);
return out;
return effectList;
}
}

Loading…
Cancel
Save