2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.dao.util.helper;
26 import java.sql.Connection;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.sql.Statement;
32 * This class provides the basic utility methods of database connection
34 * Since currently this class only contains stateless methods, the package
35 * is exported by maven-bundle-plugin. If you have to add some stateful methods
36 * in this class, one suggested solution is that use blueprint to create a singleton
37 * which is exported as service
39 public class DBHelper {
41 * Closes a database resultSet,statement and connection in that order. Data access objects should call this method
44 * @param resultSet or null
45 * @param statement or null
46 * @param connection or null
48 public static void close(ResultSet resultSet, Statement statement, Connection connection) {
50 closeResultSet(resultSet);
53 closeStatement(statement);
55 closeConnection(connection);
61 * Closes a database result set. Data access objects should call this method
62 * when a result set is no longer needed.
64 * @param rs A ResultSet Object
66 public static void closeResultSet(ResultSet rs) {
71 } catch (SQLException se) {
72 // Ignore this exception and allow execution to continue.
73 // so that connection can try to be close.
78 * Closes a database query statement. Data access objects should call this
79 * method when a statement is no longer needed.
81 * @param stmt A Statement Object
83 public static void closeStatement(Statement stmt) {
88 } catch (SQLException se) {
89 // Ignore this exception and allow execution to continue.
90 // so that connection can try to be close.
95 * Closes a database connection. Data access objects should call this method
96 * when a database connection is no longer needed.
98 * @param connection A Connection Object *
100 public static void closeConnection(Connection connection) {
102 if (connection != null && !connection.isClosed()) {
105 } catch (SQLException se) {
106 // Ignore this exception and allow execution to continue.