Java JDBC Connection Close close(Connection conn)

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

Description

close

License

Apache License

Declaration

public static void close(Connection conn) 

Method Source Code

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

import java.io.Closeable;

import java.io.Flushable;
import java.io.IOException;

import java.io.OutputStream;

import java.net.ServerSocket;
import java.net.Socket;

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

import java.util.zip.ZipFile;

public class Main {
    /**/*ww w . j ava2 s.co  m*/
     * Close zip file
     * @param zipFile
     */
    public static void close(ZipFile zipFile) {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e) {
                // When the file is closed already, can ignore this exception
            }
        }
    }

    public static void close(ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                // When the file is closed already, can ignore this exception
            }
        }
    }

    public static void close(PreparedStatement ps) {
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
                // When the file is closed already, can ignore this exception
            }
        }
    }

    public static void close(Socket sk) {
        if (sk != null) {
            try {
                sk.close();
            } catch (IOException e) {
                // When the file is closed already, can ignore this exception
                e.printStackTrace();
            }
        }
    }

    public static void close(ServerSocket ssk) {
        if (ssk != null) {
            try {
                ssk.close();
            } catch (IOException e) {
                // When the file is closed already, can ignore this exception
                //               e.printStackTrace();
            }
        }
    }

    /**
     * Close streams (in or out)
     * @param stream
     */
    public static void close(Closeable stream) {
        if (stream != null) {
            try {
                if (stream instanceof Flushable) {
                    ((Flushable) stream).flush();
                }
                stream.close();
            } catch (IOException e) {
                // When the stream is closed or interupted, can ignore this exception
            }
        }
    }

    public static void close(Connection conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                // When the conn is closed or interupted, can ignore this exception
            }
        }

    }

    public static void flush(OutputStream out) {
        if (out != null) {
            try {
                out.flush();
            } catch (IOException e) {
                //
            }
        }
    }
}

Related

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