Oracle connection pool

xiaoxiao2021-03-06  74

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;

}

转载请注明原文地址:https://www.9cbs.com/read-93401.html

New Post(0)