KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > adapter > jdbc > util > JdbcUtil


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh.adapter.jdbc.util;
22
23 import java.sql.Connection JavaDoc;
24 import java.sql.ResultSet JavaDoc;
25 import java.sql.Statement JavaDoc;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * @author mwilson
32  *
33  * TODO To change the template for this generated type comment go to
34  * Window - Preferences - Java - Code Style - Code Templates
35  */

36 public final class JdbcUtil
37 {
38    /** Commons Logger */
39    private static final Log LOGGER = LogFactory.getFactory().getInstance(JdbcUtil.class);
40
41    /** Protect singleton */
42    private JdbcUtil()
43    {
44
45    }
46
47    /** Cleans up resources.
48     *
49     * @param statement Statement to close.
50     * @param connection Connection to close.
51     */

52    public static void close(Statement JavaDoc statement, Connection JavaDoc connection)
53    {
54       try
55       {
56          statement.close();
57       }
58       catch (Exception JavaDoc ignore)
59       {
60          LOGGER.info(ignore);
61       }
62       try
63       {
64          connection.close();
65       }
66       catch (Exception JavaDoc ignore)
67       {
68          LOGGER.info(ignore);
69       }
70    }
71
72    /** Cleans up resources.
73     *
74     * @param result ResultSet to close.
75     * @param statement Statement to close.
76     * @param connection Connection to close.
77     */

78    public static void close(ResultSet JavaDoc result, Statement JavaDoc statement, Connection JavaDoc connection)
79    {
80       if (result != null)
81          try
82          {
83             result.close();
84          }
85          catch (Exception JavaDoc ignore)
86          {
87             LOGGER.info(ignore);
88          }
89       if (statement != null)
90          try
91          {
92             statement.close();
93          }
94          catch (Exception JavaDoc ignore)
95          {
96             LOGGER.info(ignore);
97          }
98       if (connection != null)
99          try
100          {
101             connection.close();
102          }
103          catch (Exception JavaDoc ignore)
104          {
105             LOGGER.info(ignore);
106          }
107    }
108 }
Popular Tags