Here you can find the source of closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)
Parameter | Description |
---|---|
preparedStatement | PreparedStatement |
connection | Connection |
resultSet | ResultSet |
public static void closeAllConnections(PreparedStatement preparedStatement, Connection connection, ResultSet resultSet)
//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); } } } }