Java SQL ResultSet Close closeAll(ResultSet rset, Statement stmt, Connection conn)

Here you can find the source of closeAll(ResultSet rset, Statement stmt, Connection conn)

Description

Close a resultset, statement, and connection returning pooled objects to their respective pools.

License

Open Source License

Declaration

public static void closeAll(ResultSet rset, Statement stmt, Connection conn) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;

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

public class Main {
    /**//  w ww . j av a  2s  .  c  o  m
     * Close a resultset, statement, and connection returning pooled 
     * objects to their respective pools.
     */
    public static void closeAll(ResultSet rset, Statement stmt, Connection conn) {
        close(rset);
        close(stmt);
        close(conn);
    }

    /**
     * Close a resultset and statement returning pooled objects to 
     * their respective pools.
     */
    public static void closeAll(ResultSet rset, Statement stmt) {
        close(rset);
        close(stmt);
    }

    /**
     * Close a resultset and its associated statement and connection
     * returning pooled objects to their respective pools.
     */
    public static void closeAll(ResultSet rset) {
        try {
            Statement stmt = rset.getStatement();
            close(rset);
            closeAll(stmt);
        } catch (SQLException se) {
        }
    }

    /**
     * Close a statement and its associated connection returning 
     * pooled objects to their respective pools.
     */
    public static void closeAll(Statement stmt) {
        try {
            Connection conn = stmt.getConnection();
            close(stmt);
            close(conn);
        } catch (SQLException se) {
        }
    }

    /**
     * Close the given result set.
     */
    public static void close(ResultSet rset) {
        if (rset != null) {
            try {
                rset.close();
            } catch (SQLException e) {
            }
        }
    }

    /**
     * Close the given statement.
     */
    public static void close(Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
            }
        }
    }

    /**
     * Close a connection returning it to the pool.
     */
    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
            }
        }
    }
}

Related

  1. closeAll(Connection conn, Statement stmt, ResultSet rs)
  2. closeAll(ResultSet rs)
  3. closeAll(ResultSet rs, Statement st, Connection conn)
  4. closeAll(ResultSet rs, Statement stmt, Connection conn)
  5. closeAll(ResultSet rs1, Statement stmt1)
  6. closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)
  7. closeConnections(Connection conn, Statement st, ResultSet res)
  8. closeCursor(Statement stmt, ResultSet rows)
  9. closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)