Java JDBC Connection Close close(Connection connection)

Here you can find the source of close(Connection connection)

Description

Closes a Connection .

License

Apache License

Parameter

Parameter Description
connection a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static void close(Connection connection) throws SQLException 

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 {
    /**//from  w  w  w . j  a va2 s.  c om
     * Closes a {@link Connection}.
     * 
     * @param connection
     * @throws SQLException
     */
    public static void close(Connection connection) throws SQLException {
        if (connection != null) {
            connection.close();
            connection = null;
        }
    }

    /**
     * Closes a {@link Statement}/{@link PreparedStatement}/{@link CallableStatement}.
     * 
     * @param statement
     * @throws SQLException
     */
    public static void close(Statement statement) throws SQLException {
        if (statement != null) {
            statement.close();
            statement = null;
        }
    }

    /**
     * Closes a {@link ResultSet}.
     * 
     * @param resultSet
     * @throws SQLException
     */
    public static void close(ResultSet resultSet) throws SQLException {
        if (resultSet != null) {
            resultSet.close();
            resultSet = null;
        }
    }
}

Related

  1. close(Connection conn)
  2. close(Connection conn)
  3. close(Connection conn)
  4. close(Connection conn)
  5. close(Connection connection)
  6. close(Connection connection)
  7. close(Connection connection)
  8. close(Connection rs)
  9. close(Object obj)