Java SQL ResultSet Close close(ResultSet resultSet, Statement statement, Connection connection)

Here you can find the source of close(ResultSet resultSet, Statement statement, Connection connection)

Description

Closes a JDBC result set, statement, and connection, ignoring any errors.

License

Open Source License

Parameter

Parameter Description
resultSet Result set
statement Statement
connection Connection

Declaration

public static SQLException close(ResultSet resultSet,
        Statement statement, Connection connection) 

Method Source Code

//package com.java2s;
/*/*w w  w .  jav a 2  s  . c  o m*/
 // This software is subject to the terms of the Eclipse Public License v1.0
 // Agreement, available at the following URL:
 // http://www.eclipse.org/legal/epl-v10.html.
 // You must accept the terms of that agreement to use this software.
 //
 // Copyright (C) 2001-2005 Julian Hyde
 // Copyright (C) 2005-2012 Pentaho and others
 // All Rights Reserved.
 */

import java.sql.*;

public class Main {
    /**
     * Closes a JDBC result set, statement, and connection, ignoring any errors.
     * If any of them are null, that's fine.
     *
     * <p>If any of them throws a {@link SQLException}, returns the first
     * such exception, but always executes all closes.</p>
     *
     * @param resultSet Result set
     * @param statement Statement
     * @param connection Connection
     */
    public static SQLException close(ResultSet resultSet,
            Statement statement, Connection connection) {
        SQLException firstException = null;
        if (resultSet != null) {
            try {
                if (statement == null) {
                    statement = resultSet.getStatement();
                }
                resultSet.close();
            } catch (SQLException e) {
                firstException = e;
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                if (firstException == null) {
                    firstException = e;
                }
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                if (firstException == null) {
                    firstException = e;
                }
            }
        }
        return firstException;
    }
}

Related

  1. close(ResultSet resultSet)
  2. close(ResultSet resultSet)
  3. close(ResultSet resultSet, CallableStatement statement, Connection connection)
  4. close(ResultSet resultSet, Statement statement, Connection connection)
  5. close(ResultSet resultSet, Statement statement, Connection connection)
  6. close(ResultSet rs)
  7. close(ResultSet rs)
  8. close(ResultSet rs)
  9. close(ResultSet rs)