PreparedStatement
Put this somewhere it's used once:
final Connection connection = DriverManager.getConnection( "jdbc:postgresql://localhost:5432/postgres?user=USERNAME&password=PASSWORD"); final PreparedStatement ps = connection.prepareStatement("SELECT supporter, survey_data FROM supports WHERE exhibit = ?");
This can be part of a method call that is done frequently:
ps.setLong(1, eid); ResultSet rs = ps.executeQuery(); List<Survey> responses = new LinkedList<>(); while (rs.next()) { responses.add(new Survey(rs)); } return responses;
This resulted in 3x the speed for the queries alone in a loop, and overall 15 -> 12ms average response time over several trials.
This isn't a huge improvement, and it will vary depending on hardware.
Postgres provides a very detailed guide to optimization which will definitely come in handy.
There was an error while loading. Please reload this page.