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

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

Description

Quietly closes JDBC objects (exceptions are swallowed).

License

Apache License

Parameter

Parameter Description
conn Connection .
stmt Statement .
rs ResultSet .

Declaration

public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) 

Method Source Code

//package com.java2s;
/**/*from   w  w  w .j a  v  a2  s. c  o m*/
 * Copyright 2013 Jee Vang
    
   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.Statement;

public class Main {
    /**
     * Quietly closes JDBC objects (exceptions are swallowed).
     * @param conn {@link Connection}.
     * @param stmt {@link Statement}.
     * @param rs {@link ResultSet}.
     */
    public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) {
        if (null != rs) {
            try {
                rs.close();
                rs = null;
            } catch (Exception ex) {
            }
        }
        if (null != stmt) {
            try {
                stmt.close();
                stmt = null;
            } catch (Exception ex) {
            }
        }
        if (null != conn) {
            try {
                conn.close();
                conn = null;
            } catch (Exception ex) {
            }
        }
    }
}

Related

  1. closeConnections(Connection conn, Statement st, ResultSet res)
  2. closeCursor(Statement stmt, ResultSet rows)
  3. closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)
  4. closeDbObjects(Connection conn, Statement stmt, ResultSet res)
  5. closeEL(ResultSet rs)
  6. closeQuietly(Connection conn, Statement stmt, ResultSet rs)
  7. closeQuietly(Connection conn, Statement stmt, ResultSet rs)
  8. closeQuietly(final ResultSet resultSet)
  9. closeQuietly(ResultSet res)