Java tutorial
/* * 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.model.DocketNotificationModel; 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 DocketNotification { /** * Gather a list of notifications for items that were docketed * * @return */ public static List<DocketNotificationModel> getQueuedNotifications() { List<DocketNotificationModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM DocketNotifications"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { DocketNotificationModel item = new DocketNotificationModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setSendTo(rs.getString("sendTo")); item.setMessageSubject(rs.getString("emailSubject")); item.setMessageBody(rs.getString("emailBody")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; } /** * Delete item from docket notification based off of ID * * @param id Integer */ public static void deleteEmailEntry(int id) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "DELETE FROM DocketNotifications WHERE id = ?"; ps = conn.prepareStatement(sql); ps.setInt(1, id); ps.executeUpdate(); } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); } } }