Java SQL ResultSet Close close(ResultSet rs, Statement stmt, Connection con)

Here you can find the source of close(ResultSet rs, Statement stmt, Connection con)

Description

Closes a result set, statement, and connection.

License

Open Source License

Parameter

Parameter Description
rs The <code>ResultSet</code> to close. If this value is <code>null</code>, no <code>ResultSet</code> is closed.
stmt The <code>Statement</code> to close. If this value is <code>null</code>, no <code>Statement</code> is closed.
con The <code>Connection</code> to close. If this value is <code>null</code>, no <code>Connection</code> is closed.

Declaration

public static void close(ResultSet rs, Statement stmt, Connection con) 

Method Source Code

//package com.java2s;
/*/*from w w  w. j  av  a  2  s.c  o m*/
 * Copyright (c) 2008 Bradley W. Kimmel
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**
     * Closes a connection.  Any <code>SQLException</code>s thrown are ignored.
     * @param con The <code>Connection</code> to close.  If this value is
     *     <code>null</code>, no action is performed.
     */
    public static void close(Connection con) {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                /* nothing to do. */
            }
        }
    }

    /**
     * Closes a result set.  Any <code>SQLException</code>s thrown are ignored.
     * @param con The <code>ResultSet</code> to close.  If this value is
     *     <code>null</code>, no action is performed.
     */
    public static void close(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                /* nothing to do. */
            }
        }
    }

    /**
     * Closes a statement.  Any <code>SQLException</code>s thrown are ignored.
     * @param con The <code>Statement</code> to close.  If this value is
     *     <code>null</code>, no action is performed.
     */
    public static void close(Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                /* nothing to do. */
            }
        }
    }

    /**
     * Closes a result set, statement, and connection.  Any
     * <code>SQLException</code>s thrown are ignored.
     * @param rs The <code>ResultSet</code> to close.  If this value is
     *     <code>null</code>, no <code>ResultSet</code> is closed.
     * @param stmt The <code>Statement</code> to close.  If this value is
     *     <code>null</code>, no <code>Statement</code> is closed.
     * @param con The <code>Connection</code> to close.  If this value is
     *     <code>null</code>, no <code>Connection</code> is closed.
     */
    public static void close(ResultSet rs, Statement stmt, Connection con) {
        close(rs);
        close(stmt);
        close(con);
    }
}

Related

  1. close(ResultSet rs, Statement ps, Connection conn)
  2. close(ResultSet rs, Statement st, Connection con)
  3. close(ResultSet rs, Statement st, Connection conn)
  4. close(ResultSet rs, Statement stmt)
  5. close(ResultSet rs, Statement stmt, Connection con)
  6. close(ResultSet rs, Statement stmt, Connection con)
  7. close(Statement statement, ResultSet resultSet)
  8. closeAll(Connection con, PreparedStatement ps, ResultSet rs)
  9. closeAll(Connection conn, Statement stmt, ResultSet rs)