Method refactored to use try-with-resources
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user