Java JDBC Connection Close closeIfNotNull(Connection conn)

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

Description

close If Not Null

License

Open Source License

Declaration

public static void closeIfNotNull(Connection conn) 

Method Source Code


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

import java.sql.*;

public class Main {
    public static void closeIfNotNull(Connection conn) {
        if (conn == null) {
            return;
        }//from  ww w  .  ja  v  a2s  . c  o  m

        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void closeIfNotNull(PreparedStatement ps) {
        if (ps == null) {
            return;
        }

        try {
            ps.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. close(Connection connection)
  2. close(Connection connection)
  3. close(Connection rs)
  4. close(Object obj)
  5. closeConnection(Closeable... closes)
  6. closeJDBC(Object obj)
  7. ClosePhase(long phaseId, Connection con)
  8. closeQuietly(MongoClient mongoClient)
  9. closeResources(Object[] resources)