Java SQL ResultSet Close close(ResultSet _rsData, Logger _logger)

Here you can find the source of close(ResultSet _rsData, Logger _logger)

Description

Closes a result set

License

Open Source License

Parameter

Parameter Description
_rsData data result set to close
_logger logger to record message if encounters errors.

Declaration

public static void close(ResultSet _rsData, Logger _logger) 

Method Source Code

//package com.java2s;
/**//w  ww .  ja va2  s.c o m
 * PureInfo Force
 * @(#)DBUtil.java   1.0 2005-7-23
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

import java.sql.ResultSet;
import java.sql.Statement;
import org.apache.log4j.Logger;

public class Main {
    /**
     * Closes a result set
     * 
     * @param _rsData
     *            data result set to close
     * @param _logger
     *            logger to record message if encounters errors.
     */
    public static void close(ResultSet _rsData, Logger _logger) {
        if (_rsData == null)
            return;

        //else
        try {
            _rsData.close();
        } catch (Exception ex) {
            if (_logger == null) {
                ex.printStackTrace(System.err);
            } else {
                _logger.error("failed to close ResultSet", ex);
            }
        }
    }

    /**
     * Closes a statement
     * 
     * @param _rsData
     *            statement to close
     * @param _logger
     *            logger to record message if encounters errors.
     */
    public static void close(Statement _statement, Logger _logger) {
        if (_statement == null)
            return;

        //else
        try {
            _statement.close();
        } catch (Exception ex) {
            if (_logger == null) {
                ex.printStackTrace(System.err);
            } else {
                _logger.error("failed to close Statement", ex);
            }
        }
    }

    /**
     * Closes a result set and related statement
     * 
     * @param _rsData
     *            data result set to close
     * @param _statement
     *            related statement
     * @param _logger
     *            logger to record message if encounters errors.
     */
    public static void close(ResultSet _rsData, Statement _statement, Logger _logger) {
        close(_rsData, _logger);
        close(_statement, _logger);
    }
}

Related

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