Used Oracle Connection Pack Import Java.util. *; Import Java.sql. *; Import Java.io. *; Import Oracle.jdbc.pool. *;
Public class dbpoolconnection {
private String url = new String (); private String user = new String (); private String password = new String (); private int imin = 0; private int imax = 0; private OracleConnectionPoolDataSource ocpds; private Connection conn = null; private OracleConnectionCacheImpl dbpool; // use private static final properties only generates a connection pool private static final DBPoolConnection dbpoolconn = new DBPoolConnection (); // constructor used to ensure that private property constructor is not called private DBPoolConnection () {if (dbpool == NULL) {getConnectionInfo (); setoraconnpoolDataSource (); setoraconncacheimpl (opds); setConn (dbpool);}}
Public static dbpoolconnection getdbpool () {return dbpoolconn;}
private boolean getConnectionInfo () {Properties prop = new Properties (); try {InputStream is = getClass () getResourceAsStream ( "/database-conf.properties");. prop.load (is); if (is = null!) { Is.close ();
} CatCH (Exception EX) {system.out.println (ex.toString ());
URL = Prop.GetProperty ("URL"); user = prop.getProperty ("user"); password = prop.getProperty ("password"); iMIN = Integer.Parseint (Prop.GetProperty ("min")); iMax = Integer.Parseint (Prop.GetProperty ("max")); return true;}
private OracleConnectionPoolDataSource setOraConnPoolDataSource () {Properties prop = new Properties (); try {ocpds = new OracleConnectionPoolDataSource (); ocpds.setURL (url); ocpds.setUser (user); ocpds.setPassword (password);} catch (Exception ex) {} return ocpds;} private OracleConnectionCacheImpl setOraConnCacheImpl (OracleConnectionPoolDataSource ds) {try {dbpool = new OracleConnectionCacheImpl (ds); dbpool.setCacheScheme (OracleConnectionCacheImpl.FIXED_WAIT_SCHEME); dbpool.setMinLimit (imin); dbpool.setMaxLimit (imax);} catch ( EXCEPTION EX) {
} Return dbpool;
Private void setConn (OracleConnectionCacheImpl ORACONNIMPL) {Try {conn = ORACONNIMPL.GETCONNECTION ();} catch (exception ex) {}}}
Public connection getConn () {Return Conn;
}