Source:
<code>private void processEvents() throws SQLException { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; List<event_audit_log_subscriber> eventSubscribers = new ArrayList<event_audit_log_subscriber>(); try { connection = ds.getConnection(); ps = connection .prepareStatement("select * from event_audit_log_subscriber_view " + "where audit_log_id <= (select max(audit_log_id) from audit_log)"); rs = ps.executeQuery(); while (rs.next()) { eventSubscribers.add(getEventAuditLogSubscriber(rs)); } } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { log.error("Failed to release resultset of event_audit_log_subscriber", e); } } if (ps != null) { try { ps.close(); } catch (SQLException e) { log.error("Failed to release statement of event_audit_log_subscriber", e); throw e; } <START> } <END> if (connection != null) { try { connection.close(); } catch (SQLException e) { log.error("Failed to close connection of event_audit_log_subscriber", e); throw e; } } } DbUser dbUser = null; for (event_audit_log_subscriber eventSubscriber:eventSubscribers) { dbUser = getUserByUserId(eventSubscriber.getsubscriber_id()); if (dbUser != null) { EventSender method = methodsMapper.getMethod(EventNotificationMethods.forValue(eventSubscriber.getmethod_id())); EventSenderResult sendResult = null; try { sendResult = method.send(eventSubscriber, dbUser.getemail()); } catch (Exception e) { log.error("Failed to dispatch message", e); sendResult = new EventSenderResult(); sendResult.setSent(false); sendResult.setReason(e.getMessage()); } addEventNotificationHistory(geteventNotificationHist(eventSubscriber, sendResult.isSent(), sendResult.getReason())); updateAuditLogEventProcessed(eventSubscriber); } } }</code><technical_language>consider utility functions close rs, ps connection called places need close them. a thought</technical_language>

Target:
private void processEvents() throws SQLException { Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; List<event_audit_log_subscriber> eventSubscribers = new ArrayList<event_audit_log_subscriber>(); try { connection = ds.getConnection(); ps = connection .prepareStatement("select * from event_audit_log_subscriber_view " + "where audit_log_id <= (select max(audit_log_id) from audit_log)"); rs = ps.executeQuery(); while (rs.next()) { eventSubscribers.add(getEventAuditLogSubscriber(rs)); } } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { log.error("Failed to release resultset of event_audit_log_subscriber", e); } } if (ps != null) { try { ps.close(); } catch (SQLException e) { log.error("Failed to release statement of event_audit_log_subscriber", e); } } if (connection != null) { try { connection.close(); } catch (SQLException e) { log.error("Failed to close connection of event_audit_log_subscriber", e); throw e; } } } DbUser dbUser = null; for (event_audit_log_subscriber eventSubscriber:eventSubscribers) { dbUser = getUserByUserId(eventSubscriber.getsubscriber_id()); if (dbUser != null) { EventSender method = methodsMapper.getMethod(EventNotificationMethods.forValue(eventSubscriber.getmethod_id())); EventSenderResult sendResult = null; try { sendResult = method.send(eventSubscriber, dbUser.getemail()); } catch (Exception e) { log.error("Failed to dispatch message", e); sendResult = new EventSenderResult(); sendResult.setSent(false); sendResult.setReason(e.getMessage()); } addEventNotificationHistory(geteventNotificationHist(eventSubscriber, sendResult.isSent(), sendResult.getReason())); updateAuditLogEventProcessed(eventSubscriber); } } }