View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.jdbc;
8   
9   import java.sql.Connection;
10  import java.sql.SQLException;
11  
12  /**
13   * Utility methods for working with various parts of JDBC.
14   */
15  public final class JdbcUtils
16  {
17  
18      private JdbcUtils()
19      {
20          // empty, just to restrict instanciation
21      }
22  
23      public static void close(Connection con) throws SQLException
24      {
25          if (con != null && !con.isClosed())
26          {
27              con.close();
28          }
29      }
30  
31      public static void commitAndClose(Connection con) throws SQLException
32      {
33          if (con != null)
34          {
35              if (!con.getAutoCommit())
36              {
37                  con.commit();
38              }
39              con.close();
40          }
41      }
42  
43      public static void rollbackAndClose(Connection con) throws SQLException
44      {
45          if (con != null)
46          {
47              if (!con.getAutoCommit())
48              {
49                  con.rollback();
50              }
51              con.close();
52          }
53      }
54  
55  }