Java SQL ResultSet Close closeResultSet(ResultSet rs)

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

Description

This will do the clean up of closing an open Statement, ResultSet and Connection if open.

License

Open Source License

Parameter

Parameter Description
rs An open ResultSet

Declaration

public static void closeResultSet(ResultSet rs) 

Method Source Code


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

public class Main {
    /**********************************
    This will do the clean up of closing an open Statement, ResultSet and Connection if open.
    @since 2006.07.24/*  w  w  w  . j a  v  a  2 s. c  o  m*/
    @param rs An open ResultSet
    **********************************/
    public static void closeResultSet(ResultSet rs) {
        try {
            if (rs != null) {
                Statement s = rs.getStatement();
                rs.close();
                if (s != null) {
                    Connection c = s.getConnection();
                    s.close();
                    if (c != null && !(c.isClosed())) {
                        c.close();
                    }
                }
            }
        } catch (Exception e) {
            //Common.handleException(e);
        }
    }
}

Related

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