Import java.sql.Connection;
Import Oracle.jdbc.pool.OracleConnectionCacheImpl; /**
* Connection Pool Management class
*/
public class Dbpool {
/** Connection Pool * *
private static Oracleconnectioncacheimpl pool = null;
/**
* Initialize Connection Pool
*/
public static void Init () {
try{
String user = "User"; User name
String password = "pwd"; Password
String host = "127.0.0.1"; Server address
String port = "1521"; Port
String sid = "Oracle92"; Sid
int max = 20; Maximum number of connections
int min = 5; Minimum number of connections
Spelling connection string
String url = "jdbc:oracle:thin:@" + Host + ":" + Port + ":" + sid;
Instantiate a connection pool and set parameters
Pool = new Oracleconnectioncacheimpl ();
Pool.seturl (URL);
Pool.setpassword (password);
Pool.setuser (user);
Pool.setmaxlimit (max);
Pool.setminlimit (min);
/**
* Set the number of connections to increase the mode of exceeding the limit.
* Dynamic_scheme: Dynamic increase. If you exceed the upper limit, turn it off.
* There are two more. 1. return directly null. 2. Always wait
*/
Pool.setcachescheme (Oracleconnectioncacheimpl.dynamic_scheme);
/**
* If you already have a connection pool.
* For example, Oracleconnectionpooldatasource Ocpds;
* Can be set directly. The previous settings are not available. or write directly in the constructor.
*/
Pool.setconnectionpooldatasource (OCPDS);
}catch (Exception ex) {
}
}
/**
* End processing.
* For example, call before app is turned off.
*/
public static void Destory () {
if (pool!= null) {
try {
Pool.close ();
Pool = null;
}catch (Exception ex) {
}
}
}
/**
* Take the connection.
* is as normal as any other connection.
* @return Connection
*/
public static Connection getconnection () {
try{
Connection conn = Pool.getconnection ();
Return conn;
}catch (Exception e) {
return null;
}
}
/**
* Debugging
*/
public static void Turnning () {
System.out.println ("Active Conns:" +pool.getactivesize ());
System.out.println ("Cached Conns:" +pool.getcachesize ());
}
}