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

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

Description

Utility function for safely closing open resultset/statement/connection

License

Open Source License

Parameter

Parameter Description
ResultSet a parameter
Statement a parameter
Connection a parameter

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;

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

public class Main {
    /**//from  ww w .  j  a va2s . co  m
     * Utility function for safely closing open resultset/statement/connection
     * 
     * @param ResultSet
     * @param Statement
     * @param Connection
     */
    public static void close(ResultSet rs, Statement stmt, Connection con) {
        if (rs != null) {
            try {
                rs.close();

            } catch (SQLException e) {
                System.out.println("The result set cannot be closed.");
            }
        }
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                System.out.println("The statement cannot be closed.");
            }
        }
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                System.out.println("The data source connection cannot be closed.");
            }
        }
    }
}

Related

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