title: JDBC Connection pooling using C3P0
body: <p>Following is my helper class to get DB connection:</p>
  
  <p>I've used the C3P0 connection pooling as described <a href="http://www.mchange.com/projects/c3p0/index.html#using_combopooleddatasource" rel="noreferrer">here</a>.</p>
  
  <pre><code>public class DBConnection {
  
      private static DataSource dataSource;
      private static final String DRIVER_NAME;
      private static final String URL;
      private static final String UNAME;
      private static final String PWD;
  
      static {
  
          final ResourceBundle config = ResourceBundle
                  .getBundle("props.database");
          DRIVER_NAME = config.getString("driverName");
          URL = config.getString("url");
          UNAME = config.getString("uname");
          PWD = config.getString("pwd");
  
          dataSource = setupDataSource();
      }
  
      public static Connection getOracleConnection() throws SQLException {
          return dataSource.getConnection();
      }
  
      private static DataSource setupDataSource() {
          ComboPooledDataSource cpds = new ComboPooledDataSource();
          try {
              cpds.setDriverClass(DRIVER_NAME);
          } catch (PropertyVetoException e) {
              e.printStackTrace();
          }
          cpds.setJdbcUrl(URL);
          cpds.setUser(UNAME);
          cpds.setPassword(PWD);
          cpds.setMinPoolSize(5);
          cpds.setAcquireIncrement(5);
          cpds.setMaxPoolSize(20);
          return cpds;
      }
  }
  </code></pre>
  
  <p>in the DAO i'll be writing something like this:</p>
  
  <pre><code>try {
              conn = DBConnection.getOracleConnection();
  
              ....
  
  
  } finally {
      try {
          if (rs != null) {
              rs.close();
          }
          if (ps != null) {
              ps.close();
          }
          if (conn != null) {
              conn.close();
          }
      } catch (SQLException e) {
          logger
                  .logError("Exception occured while closing cursors!", e);
  
      }
  </code></pre>
  
  <p>Now, my question is should I bother to do any other clean up other than closing the cursors(connection/statement/resultSet/preparedStatement) listed in the finally block.</p>
  
  <p>What is <a href="http://www.mchange.com/projects/c3p0/index.html#cleaning" rel="noreferrer">this</a> cleanup?? When and where should I do this?</p>
  
  <p>Should you find anything wrong in the above code, please point out.</p>