55. How do you implement Connection Pooling

Connection Pooling can be implemented by the following way. 

  1.  A javax.sql.ConnectionPoolDataSource interface that serves as a resource manager connection factory for pooled java.sql.Connection objects. Each database vendors provide the implementation for that interface. 
    1. For example, the oracle vendors implementation is as follows: oracle.jdbc.pool.oracleConnectionPoolDataSource Class. 
  2. A javax.sql.PooledConnection interface encapsulates the physical connection for the database. Again, the vendor provides the implementation.

Code for connecting the connection pooling

InitalContext ic=new InitialContext();

Hashtable ht=new Hashtable();

ht.put(“Context.INITIAL_PROVIDER”,weblogic.jndi.InitialCla)

//u have to set weblogic properties first and the jndi name that u r defining in 

//weblogic while creating the connectionpool

ht.put(“Context.PROVIDER_URL”,t3://localhost:7001);

ht.put(“Context.SECURITY_PRINCIPAL”,username);

ht.put(“Context.SECURITY_CREDENTIALS”,passwordof weblogic);

DataSource ds=(DataSource)ic.lookup(“jndiname”);

Connection con=ds.getConnection();

Statement stmt=con.createStatement();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: