List of usage examples for org.apache.commons.dbutils DbUtils closeQuietly
public static void closeQuietly(Statement stmt)
Statement
, avoid closing if null and hide any SQLExceptions that occur. From source file:com.sql.DocketNotification.java
/** * Gather a list of notifications for items that were docketed * /*from w w w . ja v a 2s . c om*/ * @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; }
From source file:com.sql.CaseType.java
/** * Gathers a list of active case types for finding the proper section based * on the case number./*from w w w.j a v a 2s . c om*/ * * @return List CaseTypeModel */ public static List<CaseTypeModel> getCaseTypes() { List<CaseTypeModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM CaseType WHERE active = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { CaseTypeModel item = new CaseTypeModel(); item.setId(rs.getInt("id")); item.setActive(rs.getBoolean("active")); item.setSection(rs.getString("Section")); item.setCaseType(rs.getString("caseType")); item.setDescription(rs.getString("Description")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.sql.SECExceptions.java
/** * Inserts an exception to the database/*from w ww. ja va 2s. com*/ * * @param item SECExceptionsModel * @return boolean */ public static boolean insertException(SECExceptionsModel item) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO SECExceptions (" + "className, " + "methodName, " + "exceptionType, " + "exceptionDescrption, " + "timeOccurred " + ") VALUES (" + "?, " + "?, " + "?, " + "?, " + "GETDATE())"; ps = conn.prepareStatement(sql); ps.setString(1, item.getClassName()); ps.setString(2, item.getMethodName()); ps.setString(3, item.getExceptionType()); ps.setString(4, item.getExceptionDescription()); ps.executeUpdate(); } catch (SQLException ex) { System.out.println(ex.toString()); return true; } finally { DbUtils.closeQuietly(ps); DbUtils.closeQuietly(conn); } return false; }
From source file:com.sql.SystemError.java
/** * Gathers a list of errors based on type and count total of them * * @return/*from ww w. j av a2 s.c o m*/ */ public static List<SystemErrorModel> getErrorCounts() { List<SystemErrorModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT exceptionType, COUNT(*) AS 'num' " + "FROM SystemError " + "WHERE timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) " + "AND username != 'andrew.schmidt' " + "AND username != 'anthony.perk' " + "GROUP BY exceptionType"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { SystemErrorModel item = new SystemErrorModel(); item.setExceptionType(rs.getString("exceptionType") == null ? "" : rs.getString("exceptionType")); item.setNumber(rs.getInt("num")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.sql.EmailOutRelatedCase.java
public static List<EmailOutRelatedCaseModel> getRelatedCases(EmailOutModel eml) { List<EmailOutRelatedCaseModel> list = new ArrayList(); Connection conn = null;/*from www. j a va 2s . c o m*/ PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOutRelatedCase WHERE emailOutId = ? "; ps = conn.prepareStatement(sql); ps.setInt(1, eml.getId()); rs = ps.executeQuery(); while (rs.next()) { EmailOutRelatedCaseModel item = new EmailOutRelatedCaseModel(); item.setId(rs.getInt("id")); item.setEmailOutId(rs.getInt("emailOutId")); item.setCaseYear(rs.getString("caseYear")); item.setCaseType(rs.getString("caseType")); item.setCaseMonth(rs.getString("caseMonth")); item.setCaseNumber(rs.getString("caseNumber")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.sql.Activity.java
/** * Gathers a list of tiles that are awaiting a timestamp * //w ww . j a v a2s .c o m * @return List (ActivityModel) */ public static List<ActivityModel> getFilesToStamp() { List<ActivityModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM Activity WHERE awaitingTimestamp = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { ActivityModel type = new ActivityModel(); type.setId(rs.getInt("id")); type.setCaseYear(rs.getString("caseYear")); type.setCaseType(rs.getString("caseType")); type.setCaseMonth(rs.getString("caseMonth")); type.setCaseNumber(rs.getString("caseNumber")); type.setDate(rs.getTimestamp("date")); type.setFileName(rs.getString("fileName")); list.add(type); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:ca.qc.adinfo.rouge.leaderboard.db.LeaderboardDb.java
public static boolean createLeaderboard(DBManager dbManager, String key, String name) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;// w ww.j a va 2 s . co m String sql = null; sql = "INSERT INTO rouge_leaderboards (`key`, `name`) VALUES (?, ?);"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setString(1, key); stmt.setString(2, name); int ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.sql.EmailOut.java
/** * Gathers current emails waiting to be sent out. * * @return List (EmailOutModel)/* w ww . jav a 2 s . c om*/ */ public static List<EmailOutModel> getEmailOutQueue() { List<EmailOutModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT * FROM EmailOut WHERE okToSend = 1"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { EmailOutModel item = new EmailOutModel(); item.setId(rs.getInt("id")); item.setSection(rs.getString("Section")); item.setCaseYear(rs.getString("caseYear")); item.setCaseType(rs.getString("caseType")); item.setCaseMonth(rs.getString("caseMonth")); item.setCaseNumber(rs.getString("caseNumber")); item.setTo(rs.getString("to")); item.setFrom(rs.getString("from")); item.setCc(rs.getString("cc")); item.setBcc(rs.getString("bcc")); item.setSubject(rs.getString("subject")); item.setBody(rs.getString("body")); item.setUserID(rs.getInt("UserID")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:ca.qc.adinfo.rouge.social.db.SocialDb.java
public static boolean addFriend(DBManager dbManager, long userId, long friendId) { Connection connection = null; PreparedStatement stmt = null; ResultSet rs = null;//from www . j a v a 2 s . c o m String sql = null; sql = "INSERT INTO rouge_social_friends (`user_id`, `friend_user_id`) VALUES (?, ?)"; try { connection = dbManager.getConnection(); stmt = connection.prepareStatement(sql); stmt.setLong(1, userId); stmt.setLong(2, friendId); int ret = stmt.executeUpdate(); if (ret < 1) { return false; } stmt.setLong(1, friendId); stmt.setLong(2, userId); ret = stmt.executeUpdate(); return (ret > 0); } catch (SQLException e) { log.error(stmt); log.error(e); return false; } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(connection); } }
From source file:com.sql.Audit.java
/** * Adds an entry to the audit table//w ww . ja v a2 s. c o m * @param action performed action to be stored */ public static void addAuditEntry(String action) { Connection conn = null; PreparedStatement ps = null; try { conn = DBConnection.connectToDB(); String sql = "INSERT INTO Audit VALUES" + "(?,?,?)"; ps = conn.prepareStatement(sql); ps.setTimestamp(1, new Timestamp(System.currentTimeMillis())); ps.setInt(2, 0); ps.setString(3, action == null ? "MISSING ACTION" : StringUtils.left(action, 255)); ps.executeUpdate(); } catch (SQLException ex) { if (ex.getCause() instanceof SQLServerException) { addAuditEntry(action); } } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); } }