Java SQL ResultSet Close closeQuietly(Connection conn, Statement stmt, ResultSet rs)

Here you can find the source of closeQuietly(Connection conn, Statement stmt, ResultSet rs)

Description

Close a Connection, Statement and ResultSet.

License

Apache License

Parameter

Parameter Description
conn Connection to close.
stmt Statement to close.
rs ResultSet to close.

Declaration

public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) 

Method Source Code

//package com.java2s;
/*//from   w w w . ja va2s  . c  o m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**
     * Close a <code>Connection</code>, avoid closing if null and hide any SQLExceptions that occur.
     *
     * @param conn Connection to close.
     */
    public static void closeQuietly(Connection conn) {
        try {
            close(conn);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    /**
     * Close a <code>Connection</code> and <code>Statement</code>. Avoid closing if null and hide
     * any SQLExceptions that occur.
     *
     * @param conn Connection to close.
     * @param stmt Statement to close.
     */
    public static void closeQuietly(Connection conn, Statement stmt) {
        closeQuietly(stmt);
        closeQuietly(conn);
    }

    /**
     * Close a <code>Connection</code>, <code>Statement</code> and <code>ResultSet</code>. Avoid
     * closing if null and hide any SQLExceptions that occur.
     *
     * @param conn Connection to close.
     * @param stmt Statement to close.
     * @param rs ResultSet to close.
     */
    public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) {
        closeQuietly(rs);
        closeQuietly(stmt);
        closeQuietly(conn);
    }

    /**
     * Close a <code>ResultSet</code>, avoid closing if null and hide any SQLExceptions that occur.
     *
     * @param rs ResultSet to close.
     */
    public static void closeQuietly(ResultSet rs) {
        try {
            close(rs);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    /**
     * Close a <code>Statement</code>, avoid closing if null and hide any SQLExceptions that occur.
     *
     * @param stmt Statement to close.
     */
    public static void closeQuietly(Statement stmt) {
        try {
            close(stmt);
        } catch (SQLException e) { // NOPMD
            // quiet
        }
    }

    /**
     * Close a <code>Connection</code>, avoid closing if null.
     *
     * @param conn Connection to close.
     * @throws SQLException if a database access error occurs
     */
    public static void close(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }

    /**
     * Close a <code>ResultSet</code>, avoid closing if null.
     *
     * @param rs ResultSet to close.
     * @throws SQLException if a database access error occurs
     */
    public static void close(ResultSet rs) throws SQLException {
        if (rs != null) {
            rs.close();
        }
    }

    /**
     * Close a <code>Statement</code>, avoid closing if null.
     *
     * @param stmt Statement to close.
     * @throws SQLException if a database access error occurs
     */
    public static void close(Statement stmt) throws SQLException {
        if (stmt != null) {
            stmt.close();
        }
    }
}

Related

  1. closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)
  2. closeDbObjects(Connection conn, Statement stmt, ResultSet res)
  3. closeEL(ResultSet rs)
  4. closeQuietly(Connection conn, Statement stmt, ResultSet rs)
  5. closeQuietly(Connection conn, Statement stmt, ResultSet rs)
  6. closeQuietly(final ResultSet resultSet)
  7. closeQuietly(ResultSet res)
  8. closeQuietly(ResultSet resultSet)
  9. closeQuietly(ResultSet resultSet)