Java JDBC Connection Close close(Connection conn)

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

Description

close

License

Apache License

Declaration

private static void close(Connection conn) 

Method Source Code


//package com.java2s;
/* Copyright [2014] [Xinyue Wang]
   Licensed 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.//from w w w.ja v a  2  s  . c o  m
*/

import java.sql.*;

public class Main {
    public static void close(Connection conn, Statement stmt, PreparedStatement pstm, ResultSet rs) {
        close(rs);
        close(pstm);
        close(stmt);
        close(conn);
    }

    private static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            conn = null;
        }
    }

    private static void close(Statement stmt) {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            stmt = null;
        }
    }

    private static void close(PreparedStatement pstm) {
        if (pstm != null) {
            try {
                pstm.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            pstm = null;
        }
    }

    private static void close(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            rs = null;
        }
    }
}

Related

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