If this is in regards to DB Connection Pooling, there are other options available.  
Poolman can be found at sourceforge.com.  You are correct to be concerned about 
creating multiple instances of this GetConnection class.   You can correct this by 
making a call to a static method called getConnection().  Here's an example of reading 
in a properties file and retrieving pooled connections.


import java.sql.*;
import java.util.*;
import java.io.*;
import oracle.jdbc.pool.*;
import oracle.jdbc.driver.*;
import javax.sql.*;

/**
 *      Facilitates use of pooled oracle db connections.
 *      
 *      @author David Durham
 *
 */
public class OracleConnectionManager {

        private static int stmtCacheSize = 100;
        private static OracleConnectionPoolDataSource ocpds = null;
        private static String connectString = null;
      private static String username = null;
      private static String password = null;
        
        public OracleConnectionManager() {
                createPool();
        }

        private void createPool() {
                try {
                        Properties info = null;
                        info = new Properties();
                        InputStream in = 
getClass().getResourceAsStream("/db.properties");
                        info.load(in);
                        this.stmtCacheSize = 
Integer.parseInt(info.getProperty("stmtCacheSize"));
                  ocpds = new OracleConnectionPoolDataSource();
                        ocpds.setDriverType(info.getProperty("driverType"));
                        ocpds.setServerName(info.getProperty("serverName"));
                        ocpds.setNetworkProtocol(info.getProperty("networkProtocol"));
                        ocpds.setDatabaseName(info.getProperty("databaseName"));
                        
ocpds.setPortNumber(Integer.parseInt(info.getProperty("port")));
                        ocpds.setUser(info.getProperty("user"));
                        ocpds.setPassword(info.getProperty("password"));
                } catch (Exception e) { 
                        System.err.print(e.getMessage());
                }
        }
        
        
        /**
         *      gets a connection from the connection pool
         *      @return a connection from the connection pool
         */
        public static java.sql.Connection getConnection() throws SQLException {
              if (ocpds == null) {
                        OracleConnectionManager ocm = new OracleConnectionManager();
                }
                PooledConnection pconn = null;
                try {
                        pconn = ocpds.getPooledConnection();
                        
((OraclePooledConnection)pconn).setStmtCacheSize(stmtCacheSize);
                } catch ( Exception e ) { 
                        System.err.println("Connection attempt failed: " + 
e.getMessage());
                }
                return pconn.getConnection();
        }
}




> -----Original Message-----
> From: Ashish Kulkarni [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 10, 2002 2:57 PM
> To: Tomcat Users List
> Subject: one servlet question
> 
> 
> Hi,
> I have to write a servlet which will be a base servlet
> for all servlets in my applications.
> I have a class called GetConnection which gets the
> connection from servletcontext depending upon some
> parameters in the session, so i have go send
> servletcontext, and session to this class.
> now the question is should i create the instance of
> this class in init method of the servlet or define a
> seperate method and create the instance of that class
> from doget or dopost method of the child servlet,(this
> servlet will extend the base servlet).
> i have this doubt because if i  create the instance of
> this getconnection class in init method, it will be in
> memory for the full life cycle of servlet(i.e. untill
> i stop the app server).
> so if i extend this base servlet for other 100 child
> servlets, then there will be 100 instance of
> getconnection for life cycle of servlet.
> so am i thinking in the right way???
> any suggestions
> Ashish
> 
> __________________________________________________
> Yahoo! - We Remember
> 9-11: A tribute to the more than 3,000 lives lost
> http://dir.remember.yahoo.com/tribute
> 
> --
> To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to