Differences in obtaining connection pools I'm trying to understand the difference between two ways to get a connection from a Weblogic 6.0 connection pool.

Robert Castaneda

The two different ways that we can get a connection from a pool are listed as follows(taken from the original posting from the author).

1. Have a connection pool manager with a getConnection method that uses the following code:

Connection conn  = null;
Driver myDriver =(Driver)Class.forName("weblogic.jdbc.pool.Driver").newInstance();
Properties props = new Properties();
conn = myDriver.connect("jdbc:weblogic:pool", props);

2. Using JNDI and providing a URL (such as PROVIDER_URL below) for the machine the connection pool is on. The following code could be used in a ConnectionPoolManager class too:
Context ctx = null;
Hashtable ht = new Hashtable();

try {    
  ctx = new InitialContext(ht);    
  javax.sql.DataSource ds =(javax.sql.DataSource) ctx.lookup("myJtsDataSource");   
  java.sql.Connection conn = ds.getConnection(); 
} catch (Exception ex) {}

The underlying result is the same. However, using a DataSource is the newer and much preferred method as the developer does not tie themselves to a particular driver or connection pool. There is also the added flexibility of changing connection pool properties without modifying the code.