01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.helper;
16:
17: import java.sql.Connection;
18: import java.sql.ResultSet;
19: import java.sql.Statement;
20: import org.apache.commons.logging.Log;
21: import org.apache.commons.logging.LogFactory;
22:
23: /**
24: * Utility class providing some general methods for manipulating connection to the database.
25: * NB! Every and one class and/or method that utilizes database connection, statement and/or result set
26: * should use this class.
27: *
28: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
29: *
30: */
31: public class DbUtil {
32: private static final Log log = LogFactory.getLog(DbUtil.class);
33:
34: private DbUtil() {
35: // static methods only - hide constructor
36: }
37:
38: /**
39: * Closes connection to the database along with current statement and result set.
40: * @param con connection to be closed.
41: * @param stmt statement to be closed.
42: * @param rs result set to be closed.
43: */
44: public static void closeDbObjects(Connection con, Statement stmt,
45: ResultSet rs) {
46: if (rs != null) {
47: try {
48: rs.close();
49: } catch (Exception e) {
50: log.warn("Resultset can not be closed.", e);
51: }
52: }
53: if (stmt != null) {
54: try {
55: stmt.close();
56: } catch (Exception e) {
57: log.warn("Statement can not be closed.", e);
58: }
59: }
60: if (con != null) {
61: try {
62: con.close();
63: } catch (Exception e) {
64: log.warn("Connection can not be closed.", e);
65: }
66: }
67: }
68: }
|