/** * Gets the registered shooters present in the database, along with the name of the club they * belong to. */ public List<Shooter> getShooters() { String selectSql = "SELECT shooters.id, shooters.name, clubs.club FROM shooters JOIN clubs ON shooters.club = clubs.id"; List<Shooter> shooters = new ArrayList<Shooter>(); try (Connection conn = connector.getConnection(); ) { ResultSet dbResult = null; PreparedStatement ps = null; try { ps = DBUtils.makePreparedStatement(conn, selectSql, new Object[0]); dbResult = ps.executeQuery(); while (dbResult.next()) { Shooter shooter = new Shooter(); shooter.setId(dbResult.getInt(1)); shooter.setShooterName(dbResult.getString(2)); shooter.setClubName(dbResult.getString(3)); shooters.add(shooter); } } finally { if (dbResult != null) { dbResult.close(); } if (ps != null) { ps.close(); } } } catch (SQLException e) { throw new IllegalStateException( "Could not retrieve the clubs for with the SQL '" + selectSql + "'.", e); } return shooters; }