Java SQL ResultSet Close close(ResultSet rs, Statement st, Connection con)

Here you can find the source of close(ResultSet rs, Statement st, Connection con)

Description

Close connection

License

Apache License

Parameter

Parameter Description
rs a parameter
st a parameter
con a parameter

Declaration

public static void close(ResultSet rs, Statement st, Connection con) 

Method Source Code

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

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**/*ww  w.j a v a  2s .  co m*/
     * Close connection
     *
     * @param rs
     * @param st
     * @param con
     */
    public static void close(ResultSet rs, Statement st, Connection con) {
        try {
            try {
                if (rs != null) {
                    rs.close();
                }
            } finally {
                try {
                    if (st != null) {
                        st.close();
                    }
                } finally {
                    if (con != null) {
                        con.close();
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Close connection
     *
     * @param rs
     */
    public static void close(ResultSet rs) {
        Statement st = null;
        Connection con = null;
        try {
            try {
                if (rs != null) {
                    st = rs.getStatement();
                    rs.close();
                }
            } finally {
                try {
                    if (st != null) {
                        con = st.getConnection();
                        st.close();
                    }
                } finally {
                    if (con != null) {
                        con.close();
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Close connection
     *
     * @param st
     * @param con
     */
    public static void close(Statement st, Connection con) {
        try {
            try {
                if (st != null) {
                    st.close();
                }
            } finally {
                if (con != null) {
                    con.close();
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. close(ResultSet rs)
  2. close(ResultSet rs)
  3. close(ResultSet rs, PreparedStatement pstmt, Connection con)
  4. close(ResultSet rs, Statement ps, Connection con)
  5. close(ResultSet rs, Statement ps, Connection conn)
  6. close(ResultSet rs, Statement st, Connection conn)
  7. close(ResultSet rs, Statement stmt)
  8. close(ResultSet rs, Statement stmt, Connection con)
  9. close(ResultSet rs, Statement stmt, Connection con)