Java SQL ResultSet Close close(Connection c, Statement s, ResultSet r)

Here you can find the source of close(Connection c, Statement s, ResultSet r)

Description

close

License

Open Source License

Declaration

public static void close(Connection c, Statement s, ResultSet r) 

Method Source Code


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

public class Main {
    public static void close(Connection c, Statement s, ResultSet r) {
        try {/*from  w w  w.j a v  a2s  .  co  m*/
            if (r != null)
                r.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            if (s != null)
                s.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            if (c != null && !c.isClosed()) {
                if (c.isReadOnly()) {
                    c.setReadOnly(false);
                }
                c.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //
            // This block is required since the isReadOnly and setReadOnly methods
            // can throw exceptions
            //
            try {
                c.close();
            } catch (Exception ex) {
                // Here we don't log anything since a lot of time this method is
                // called twince with the same connection and in this case (that is
                // not an error case) the exception will be logged. We don't want
                // these stacktrace.
            }
        }
    }
}

Related

  1. close(Connection con, Statement stmt, ResultSet rs)
  2. close(Connection conn, PreparedStatement ps, ResultSet rs)
  3. close(Connection conn, Statement st, ResultSet rs)
  4. close(Connection conn, Statement st, ResultSet rs)