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

Loading…
Cancel
Save