com.sql.SystemErrorEmailList.java Source code

Java tutorial

Introduction

Here is the source code for com.sql.SystemErrorEmailList.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sql;

import com.util.ExceptionHandler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.DbUtils;

/**
 *
 * @author Andrew
 */
public class SystemErrorEmailList {

    /**
     * Gathers a list of active email addresses to send to for the email
     * for the daily crash report email.
     * 
     * @return
     */
    public static List<String> getActiveEmailAddresses() {
        List<String> list = new ArrayList();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DBConnection.connectToDB();
            String sql = "SELECT EmailAddress " + "FROM SystemErrorEmailList " + "WHERE active = 1";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                if (rs.getString("EmailAddress") != null) {
                    list.add(rs.getString("EmailAddress"));
                }
            }
        } catch (SQLException ex) {
            ExceptionHandler.Handle(ex);
        } finally {
            DbUtils.closeQuietly(conn);
            DbUtils.closeQuietly(ps);
            DbUtils.closeQuietly(rs);
        }
        return list;
    }

}