Java SQL ResultSet Close closeResultSet(ResultSet rs)

Here you can find the source of closeResultSet(ResultSet rs)

Description

Close the given JDBC ResultSet and ignore any thrown exception.

License

Apache License

Parameter

Parameter Description
rs the JDBC ResultSet to close (may be <code>null</code>)

Declaration

public static void closeResultSet(ResultSet rs) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    /**//w  ww. ja  v a2 s. c o m
     * Close the given JDBC ResultSet and ignore any thrown exception.
     * This is useful for typical finally blocks in manual JDBC code.
     *
     * @param rs the JDBC ResultSet to close (may be <code>null</code>)
     */
    public static void closeResultSet(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException ex) {
                //                logger.debug("Could not close JDBC ResultSet", ex);
            } catch (Throwable ex) {
                // We don't trust the JDBC driver: It might throw RuntimeException or Error.
                //                logger.debug("Unexpected exception on closing JDBC ResultSet", ex);
            }
        }
    }

    public static void close(ResultSet rs, Statement stmt) {
        closeResultSet(rs);
        closeStatement(stmt);
    }

    /**
     * Close the given JDBC Statement and ignore any thrown exception.
     * This is useful for typical finally blocks in manual JDBC code.
     *
     * @param stmt the JDBC Statement to close (may be <code>null</code>)
     */
    public static void closeStatement(Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException ex) {
                //                logger.debug("Could not close JDBC Statement", ex);
            } catch (Throwable ex) {
                // We don't trust the JDBC driver: It might throw RuntimeException or Error.
                //                logger.debug("Unexpected exception on closing JDBC Statement", ex);
            }
        }
    }
}

Related

  1. closeResultSet(ResultSet rs)
  2. closeResultSet(ResultSet rs)
  3. closeResultSet(ResultSet rs)
  4. closeResultSet(ResultSet rs)
  5. closeResultSet(ResultSet rs)
  6. closeResultSet(ResultSet rs)
  7. closeResultSetAndStatement(ResultSet rs)
  8. closeResultSetAndStatement(Statement statement, ResultSet resultSet)
  9. closeResultSets(List results)