Java SQL ResultSet Close closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)

Here you can find the source of closeDatabaseResources(PreparedStatement prepStmt, ResultSet rs, Connection con)

Description

This method releases this PrepareStatement,ResultSet and Connection object's database and JDBC resources.

License

Open Source License

Parameter

Parameter Description
prepStmt a parameter
rs a parameter
con a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static void closeDatabaseResources(PreparedStatement prepStmt,
        ResultSet rs, Connection con) throws SQLException 

Method Source Code

//package com.java2s;
/*/*from ww w  .j  a v a 2 s.  co  m*/
 Copyright (c) Microsoft Open Technologies, Inc.  All rights reserved.
    
 The MIT License (MIT)
    
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
    
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
    
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 */

import java.sql.Connection;

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

public class Main {
    /**
     * This method releases this PrepareStatement,ResultSet and Connection
     * object's database and JDBC resources.
     * 
     * @param prepStmt
     * @param rs
     * @param con
     * @throws SQLException
     */
    public static void closeDatabaseResources(PreparedStatement prepStmt,
            ResultSet rs, Connection con) throws SQLException {
        if (prepStmt != null) {
            prepStmt.close();
        }
        if (rs != null) {
            rs.close();
        }
        if (con != null) {
            con.close();
        }

    }

    /**
     * This method releases this Connection and PrepareStatement object's
     * database and JDBC resources.
     * 
     * @param prepStmt
     * @param con
     * @throws SQLException
     */
    public static void closeDatabaseResources(PreparedStatement prepStmt,
            Connection con) throws SQLException {
        if (prepStmt != null) {
            prepStmt.close();
        }

        if (con != null) {
            con.close();
        }

    }

    /**
     * This method releases this ResutlSet and PrepareStatement object's
     * database and JDBC resources.
     * 
     * @param prepStmt
     * @param rs
     * @throws SQLException
     */
    public static void closeDatabaseResources(PreparedStatement prepStmt,
            ResultSet rs) throws SQLException {
        if (prepStmt != null) {
            prepStmt.close();
        }
        if (rs != null) {
            rs.close();
        }

    }
}

Related

  1. closeAll(ResultSet rs1, Statement stmt1)
  2. closeAll(ResultSet rset, Statement stmt, Connection conn)
  3. closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)
  4. closeConnections(Connection conn, Statement st, ResultSet res)
  5. closeCursor(Statement stmt, ResultSet rows)
  6. closeDbObjects(Connection conn, Statement stmt, ResultSet res)
  7. closeEL(ResultSet rs)
  8. closeQuietly(Connection conn, Statement stmt, ResultSet rs)
  9. closeQuietly(Connection conn, Statement stmt, ResultSet rs)