View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.mitosis.store.derby;
21  
22  
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import java.sql.Connection;
27  import java.sql.ResultSet;
28  import java.sql.SQLException;
29  import java.sql.Statement;
30  
31  
32  class SQLUtil
33  {
34      private static final Logger LOG = LoggerFactory.getLogger( SQLUtil.class );
35  
36  
37      static void cleanup( Connection con, Statement stmt, ResultSet rs )
38      {
39          if ( rs != null )
40          {
41              try
42              {
43                  rs.close();
44              }
45              catch ( SQLException e )
46              {
47                  LOG.error( "Failed to close result set.", e );
48              }
49          }
50          if ( stmt != null )
51          {
52              try
53              {
54                  stmt.close();
55              }
56              catch ( SQLException e )
57              {
58                  LOG.error( "Failed to close statement.", e );
59              }
60          }
61          if ( con != null )
62          {
63              try
64              {
65                  con.close();
66              }
67              catch ( SQLException e )
68              {
69                  LOG.error( "Failed to close jdbc connection.", e );
70              }
71          }
72      }
73  }