title: Oracle Connection Pool Class
body: <p>I want to setup a connection pool for a Oracle DB in a Helper class.</p>
  
  <pre><code>public class DbConnection {
  
  // Data source for the pooled connection
  private static OracleDataSource dataSource;
  
  // Host
  private static final String dbHost = "bla";
  
  // Port
  private static final String dbPort = "1521";
  
  // DBname
  private static final String database = "orcl";
  
  // DBuser
  private static final String dbUser = "bla";
  
  // DBpassword
  private static final String dbPassword = "bla";
  
  static {
      OracleConnectionPoolDataSource opds;
      try {
          opds = new OracleConnectionPoolDataSource();
          opds.setURL("jdbc:oracle:thin:@" + dbHost + ":" + dbPort + ":"
                  + database);
          opds.setUser(dbUser);
          opds.setPassword(dbPassword);
          dataSource = opds;
      } catch (SQLException e1) {
          System.err.println("Connection failed!");
      }
      try {
          // Load driver
          Class.forName("oracle.jdbc.driver.OracleDriver");
  
      } catch (ClassNotFoundException e) {
          System.out.println("Driver not found!");
      }
  }
  
  public static Connection getConnection() throws SQLException {
      return dataSource.getConnection();
  }
  }
  </code></pre>
  
  <p>This is working but it is not awfully fast so I think I'm missing something to get the pooling working. Any suggestions?</p>
  
  <p>So my externel classes just invoke the getConnection() method ...</p>
  
  <pre><code>Connection conn = DbConnection.getConnection();
  ...
  conn.close();
  </code></pre>