Java SQL ResultSet Close closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)

Here you can find the source of closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)

Description

Utility method to close the connection streams.

License

Open Source License

Parameter

Parameter Description
preparedStatement PreparedStatement
connection Connection
resultSet ResultSet

Declaration

public static void closeAllConnections(PreparedStatement preparedStatement, Connection connection,
        ResultSet resultSet) 

Method Source Code

//package com.java2s;
/*/*from  w  ww  .  j  a  v  a2  s  . c  o m*/
*  Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. 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 {
    /**
     * Utility method to close the connection streams.
     *
     * @param preparedStatement PreparedStatement
     * @param connection        Connection
     * @param resultSet         ResultSet
     */
    public static void closeAllConnections(PreparedStatement preparedStatement, Connection connection,
            ResultSet resultSet) {
        closeConnection(connection);
        closeResultSet(resultSet);
        closeStatement(preparedStatement);
    }

    /**
     * Close Connection
     *
     * @param dbConnection Connection
     */
    private static void closeConnection(Connection dbConnection) {
        if (dbConnection != null) {
            try {
                dbConnection.close();
            } catch (SQLException e) {
                e.printStackTrace();
                // log.warn("Database error. Could not close database connection. Continuing with " +
                //        "others. - " + e.getMessage(), e);
            }
        }
    }

    /**
     * Close ResultSet
     *
     * @param resultSet ResultSet
     */
    private static void closeResultSet(ResultSet resultSet) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
                //System.out.println("Database error. Could not close ResultSet  - " + e.getMessage(), e);
            }
        }

    }

    /**
     * Close PreparedStatement
     *
     * @param preparedStatement PreparedStatement
     */
    private static void closeStatement(PreparedStatement preparedStatement) {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                e.printStackTrace();
                //log.warn("Database error. Could not close PreparedStatement. Continuing with" +
                //       " others. - " + e.getMessage(), e);
            }
        }

    }
}

Related

  1. closeAll(ResultSet rs)
  2. closeAll(ResultSet rs, Statement st, Connection conn)
  3. closeAll(ResultSet rs, Statement stmt, Connection conn)
  4. closeAll(ResultSet rs1, Statement stmt1)
  5. closeAll(ResultSet rset, Statement stmt, Connection conn)
  6. closeConnections(Connection conn, Statement st, ResultSet res)
  7. closeCursor(Statement stmt, ResultSet rows)
  8. closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)
  9. closeDbObjects(Connection conn, Statement stmt, ResultSet res)