Java JDBC Connection Close close(Connection connection)

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

Description

Close a connection

License

Apache License

Declaration

public static void close(Connection connection) 

Method Source Code

//package com.java2s;
/****************************************************************
 * Licensed to the AOS Community (AOS) under one or more        *
 * contributor license agreements.  See the NOTICE file         *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The AOS licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 ****************************************************************/

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**/*from   w w w  .  j  a  va2s  .c  om*/
     * Close a result set
     */
    public static void close(ResultSet results) {
        try {
            if (results != null)
                results.close();
        } catch (SQLException exception) {
        }
    }

    /**
     * Close a connection
     */
    public static void close(Connection connection) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Close a prepared statement
     */
    public static void close(PreparedStatement stmt) {
        try {
            if (stmt != null)
                stmt.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    /**
     * Close all resources
     */
    public static void close(Connection connection, PreparedStatement stmt, ResultSet results) {
        close(results);
        close(stmt);
        close(connection);
    }
}

Related

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