Java JDBC Connection Close closeJDBC(Object obj)

Here you can find the source of closeJDBC(Object obj)

Description

Utility method to safety close various jdbc objects ResultSet, Statement, PreparedStatement

License

Open Source License

Declaration

public static void closeJDBC(Object obj) 

Method Source Code

//package com.java2s;
/** ***************************************************************
Util.java//from   w w  w .  j av a 2  s.c  om
Copyright (C) 2001  Brendon Upson 
http://www.wnc.net.au info@wnc.net.au
    
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    
 *************************************************************** */

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

import java.sql.Statement;

public class Main {
    /**
     * Utility method to safety close various jdbc objects
     * ResultSet, Statement, PreparedStatement
     */
    public static void closeJDBC(Object obj) {
        if (obj == null)
            return;

        try {
            if (obj instanceof ResultSet)
                ((ResultSet) obj).close();
            if (obj instanceof Statement)
                ((Statement) obj).close();
            if (obj instanceof PreparedStatement)
                ((PreparedStatement) obj).close();
        } catch (Exception e) {
        }
    }
}

Related

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