Example usage for org.apache.commons.dbutils DbUtils closeQuietly

List of usage examples for org.apache.commons.dbutils DbUtils closeQuietly

Introduction

In this page you can find the example usage for org.apache.commons.dbutils DbUtils closeQuietly.

Prototype

public static void closeQuietly(Statement stmt) 

Source Link

Document

Close a Statement, avoid closing if null and hide any SQLExceptions that occur.

Usage

From source file:com.sql.EmailOutAttachment.java

/**
 * Deletes attachment based off of email ID
 * /*from  w  w  w. j a v a2 s  .  co m*/
 * @param id Integer
 */
public static void deleteAttachmentsForEmail(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOutAttachment WHERE emailOutID = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, id);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sql.SECExceptions.java

/**
 * Removes old exception based off of a global exception date timeframe
 *//*w ww . j  a  va 2s.com*/
public static void removeOldExceptions() {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM SECExceptions WHERE " + "timeOccurred < dateadd("
                + Global.getExceptionTimeFrame() + ",-" + Global.getExceptionTimeAmount() + ", getdate())";
        ps = conn.prepareStatement(sql);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sql.EmailOutRelatedCase.java

/**
 * Deletes related case based off of email ID
 * /*from w ww  .  j a va 2s .c  o  m*/
 * @param emailOutId Integer
 */
public static void deleteEmailOutRelatedForEmail(int emailOutId) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOutRelatedCase WHERE emailOutID = ?";
        ps = conn.prepareStatement(sql);
        ps.setInt(1, emailOutId);
        ps.executeUpdate();
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
}

From source file:com.sql.EMail.java

/**
 * Inserts email message into email table.
 *
 * @param eml EmailMessageModel//from www  .j  a v  a2 s  . c o m
 * @return Integer - generated key of the email
 */
public static int InsertEmail(EmailMessageModel eml) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "INSERT INTO EMail (" + "section, " + "emailFrom, " + "emailTo, " + "emailSubject, "
                + "sentDate, " + "receivedDate, " + "emailCC, " + "emailBCC, " + "emailBody, "
                + "emailBodyFileName, " + "readyToFile " + ") VALUES (" + "?, " //1
                + "?, " //2
                + "?, " //3
                + "?, " //4
                + "?, " //5
                + "?, " //6
                + "?, " //7
                + "?, " //8
                + "?, " //9
                + "?, " //10
                + "0)"; // Ready to File False
        ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
        ps.setString(1, StringUtils.left(eml.getSection(), 4));
        ps.setString(2, StringUtils.left(eml.getEmailFrom(), 200));
        ps.setString(3, eml.getEmailTo());
        ps.setString(4, eml.getEmailSubject());
        ps.setTimestamp(5, eml.getSentDate());
        ps.setTimestamp(6, eml.getReceivedDate());
        ps.setString(7, eml.getEmailCC());
        ps.setString(8, eml.getEmailBCC());
        ps.setString(9, eml.getEmailBody());
        ps.setString(10, eml.getEmailBodyFileName());
        ps.executeUpdate();
        ResultSet newRow = ps.getGeneratedKeys();
        if (newRow.next()) {
            return newRow.getInt(1);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
    }
    return 0;
}

From source file:com.sql.Activity.java

/**
 * Updates activity set to no longer awaiting timestamp for items that have 
 * been properly stamped//  w  w  w  .j  a  va 2 s . co  m
 * 
 * @param id Integer
 */
public static void markEntryStamped(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "UPDATE Activity SET awaitingTimestamp = 0 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);
    }
}

From source file:de.unibremen.informatik.tdki.combo.data.DBConnPool.java

public void releaseConnection(Connection c) {
    if (c != null && c == connection) {
        DbUtils.closeQuietly(connection);
    }
}

From source file:azkaban.database.AzkabanConnectionPoolTest.java

@Test
public void testConnectionDefaultAutoCommit() throws Exception {
    Assert.assertEquals(connection.getAutoCommit(), true);
    DbUtils.closeQuietly(connection);
}

From source file:com.sql.EmailOut.java

/**
 * Deletes email entry based off of the ID
 *
 * @param id Integer - emailID from the database
 *//*from   w  ww  .ja va 2 s. c om*/
public static void deleteEmailEntry(int id) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "DELETE FROM EmailOut 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);
    }
}

From source file:com.splicemachine.derby.test.framework.SpliceUserWatcher.java

@Override
protected void starting(Description description) {
    Connection connection = null;
    Statement statement = null;// ww w .j  a  v  a 2s.c o  m
    ResultSet rs = null;
    try {
        dropAndCreateUser(userName, password);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(statement);
        DbUtils.commitAndCloseQuietly(connection);
    }
    super.starting(description);
}

From source file:com.sql.EmailOutInvites.java

/**
 * Get a list of all of the email invites awaiting to be sent.
 * /*from ww w  . ja  va2 s .c  o m*/
 * @return List EmailOutInvitesModel
 */
public static List<EmailOutInvitesModel> getQueuedEmailInvites() {
    List<EmailOutInvitesModel> list = new ArrayList();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = DBConnection.connectToDB();
        String sql = "SELECT * FROM EmailOutInvites";
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();
        while (rs.next()) {
            EmailOutInvitesModel item = new EmailOutInvitesModel();
            item.setId(rs.getInt("id"));
            item.setSection(rs.getString("Section") == null ? "" : rs.getString("Section"));
            item.setToAddress(rs.getString("TOaddress") == null ? "" : rs.getString("TOaddress"));
            item.setCcAddress(rs.getString("CCaddress") == null ? "" : rs.getString("CCaddress"));
            item.setEmailBody(rs.getString("emailBody") == null ? "" : rs.getString("emailBody"));
            item.setCaseNumber(rs.getString("caseNumber") == null ? "" : rs.getString("caseNumber"));
            item.setHearingType(rs.getString("hearingType") == null ? "" : rs.getString("hearingType"));
            item.setHearingRoomAbv(
                    rs.getString("hearingRoomAbv") == null ? "" : rs.getString("hearingRoomAbv"));
            item.setHearingDescription(
                    rs.getString("hearingDescription") == null ? "" : rs.getString("hearingDescription"));
            item.setHearingStartTime(
                    CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingStartTime")));
            item.setHearingEndTime(CalendarCalculation.adjustTimeZoneOffset(rs.getTimestamp("hearingEndTime")));
            item.setEmailSubject(rs.getString("emailSubject") == null ? "" : rs.getString("emailSubject"));
            list.add(item);
        }
    } catch (SQLException ex) {
        ExceptionHandler.Handle(ex);
    } finally {
        DbUtils.closeQuietly(conn);
        DbUtils.closeQuietly(ps);
        DbUtils.closeQuietly(rs);
    }
    return list;
}