Java SQL ResultSet Close closeResource(Connection conn, Statement stmt, ResultSet rs)

Here you can find the source of closeResource(Connection conn, Statement stmt, ResultSet rs)

Description

Closes the resource if they are available.

License

Open Source License

Parameter

Parameter Description
conn the <code>Connection</code> to close.
stmt the <Code>Statement</code> to close.
rs the <code>ResultSet</code> to close.

Declaration

static final void closeResource(Connection conn, Statement stmt, ResultSet rs) 

Method Source Code


//package com.java2s;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**/*from  w  ww  . j  a v  a  2s. c  o m*/
     * Closes the resource if they are available.
     * @param conn the <code>Connection</code> to close.
     * @param stmt the <Code>Statement</code> to close.
     * @param rs the <code>ResultSet</code> to close.
     */
    static final void closeResource(Connection conn, Statement stmt, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                // ignore
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                // ignore
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                // ignore
            }
        }
    }
}

Related

  1. closeQuietly(final ResultSet resultSet)
  2. closeQuietly(ResultSet res)
  3. closeQuietly(ResultSet resultSet)
  4. closeQuietly(ResultSet resultSet)
  5. closeQuietly(ResultSet rs)
  6. closeResources(Connection conn, Statement pstmt, ResultSet rs)
  7. closeResources(Connection conn, Statement stmt, ResultSet rs)
  8. closeResources(Connection conn2, Statement statement, ResultSet rs)
  9. closeResultAndStatement(Statement statement, ResultSet resultSet)