2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.dao.util.helper;
27 import java.sql.Connection;
28 import java.sql.ResultSet;
29 import java.sql.SQLException;
30 import java.sql.Statement;
33 * This class provides the basic utility methods of database connection
35 * Since currently this class only contains stateless methods, the package
36 * is exported by maven-bundle-plugin. If you have to add some stateful methods
37 * in this class, one suggested solution is that use blueprint to create a singleton
38 * which is exported as service
40 public class DBHelper {
42 * Closes a database resultSet,statement and connection in that order. Data access objects should call this method
45 * @param resultSet or null
46 * @param statement or null
47 * @param connection or null
49 public static void close(ResultSet resultSet, Statement statement, Connection connection) {
51 closeResultSet(resultSet);
54 closeStatement(statement);
56 closeConnection(connection);
62 * Closes a database result set. Data access objects should call this method
63 * when a result set is no longer needed.
65 * @param rs A ResultSet Object
67 public static void closeResultSet(ResultSet rs) {
72 } catch (SQLException se) {
73 // Ignore this exception and allow execution to continue.
74 // so that connection can try to be close.
79 * Closes a database query statement. Data access objects should call this
80 * method when a statement is no longer needed.
82 * @param stmt A Statement Object
84 public static void closeStatement(Statement stmt) {
89 } catch (SQLException se) {
90 // Ignore this exception and allow execution to continue.
91 // so that connection can try to be close.
96 * Closes a database connection. Data access objects should call this method
97 * when a database connection is no longer needed.
99 * @param connection A Connection Object *
101 public static void closeConnection(Connection connection) {
103 if (connection != null && !connection.isClosed()) {
106 } catch (SQLException se) {
107 // Ignore this exception and allow execution to continue.