Java SQL ResultSet Close close(ResultSet resultSet)

Here you can find the source of close(ResultSet resultSet)

Description

Close or try to close the result set.

License

Apache License

Parameter

Parameter Description
resultSet the result set to close; can be null.

Return

true if result set is closed, otherwise false.

Declaration

public static boolean close(ResultSet resultSet) 

Method Source Code


//package com.java2s;
/*//from ww  w  .  j a v  a2s.co  m
 * Copyright 2008-2012 Ruslan Khmelyuk.
 *
 * Licensed 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 or try to close the connection.
     * If connection is <code>null</code> or is closed or can't be closed, than this function
     * returns <code>false</code>
     *
     * @param connection the connection to close; can be null.
     * @return true if connection is closed, otherwise false.
     */
    public static boolean close(Connection connection) {
        try {
            if (connection != null && !connection.isClosed()) {
                connection.close();
                return true;
            }
        } catch (SQLException e) {
            // ignore, but return false
        }
        return false;
    }

    /**
     * Close or try to close the statement.
     * If statement is <code>null</code> or can't be closed, than this function
     * returns <code>false</code>
     *
     * @param statement the statement to close; can be null.
     * @return true if statement is closed, otherwise false.
     */
    public static boolean close(Statement statement) {
        try {
            if (statement != null) {
                statement.close();
                return true;
            }
        } catch (SQLException e) {
            // ignore, but return false
        }
        return false;
    }

    /**
     * Close or try to close the result set.
     * If result set is <code>null</code> or can't be closed, than this function
     * returns <code>false</code>
     *
     * @param resultSet the result set to close; can be null.
     * @return true if result set is closed, otherwise false.
     */
    public static boolean close(ResultSet resultSet) {
        try {
            if (resultSet != null) {
                resultSet.close();
                return true;
            }
        } catch (SQLException e) {
            // ignore, but return false
        }
        return false;
    }
}

Related

  1. close(Connection connection, PreparedStatement statement, ResultSet resultSet)
  2. close(Connection connection, Statement statement, ResultSet resultSet)
  3. close(final PreparedStatement ps, final ResultSet rs)
  4. close(final ResultSet rs, final Statement st)
  5. close(ResultSet _rsData, Logger _logger)
  6. close(ResultSet resultSet)
  7. close(ResultSet resultSet)
  8. close(ResultSet resultSet)
  9. close(ResultSet resultSet, CallableStatement statement, Connection connection)