⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccache2.java

📁 Java示例100
💻 JAVA
字号:
/** *  JDBC 2.0 Spec doesn't mandate that JDBC vendors implement a *  Connection Cache. However, we implemented a basic one with 2 *  schemes as an Example. * *  There are 3 cache schemes: DYNAMIC_SCHEME (default) *                             FIXED_RETURN_NULL_SCHEME *                             FIXED_WAIT_SCHEME * *  A Sample demo to illustrate FIXED_RETURN_NULL_SCHEME of  *  OracleConnectionCacheImpl. *  Fixed with NoWait :  At no instance there will be no  more active  *  connections than the  the Maximum limit. Request for new connections  *  beyond the max limit will return null. *  Please compare with CCache1.java and CCache3.java  *  Please use jdk1.2 or later version */// You need to import the java.sql package to use JDBCimport java.sql.*;import javax.sql.*;import oracle.jdbc.*;import oracle.jdbc.pool.*;public class CCache2 {  public static void main (String args [])       throws SQLException  {    String url = "jdbc:oracle:oci8:@";    try {      String url1 = System.getProperty("JDBC_URL");      if (url1 != null)        url = url1;    } catch (Exception e) {      // If there is any security exception, ignore it      // and use the default    }    // Create a OracleConnectionPoolDataSource as an factory    // of PooledConnections for the Cache to create.    OracleConnectionPoolDataSource ocpds =                               new OracleConnectionPoolDataSource();    ocpds.setURL(url);    ocpds.setUser("hr");    ocpds.setPassword("hr");    // Associate it with the Cache    OracleConnectionCacheImpl ods = new OracleConnectionCacheImpl(ocpds);    // Set the Max Limit    ods.setMaxLimit (3);    // Set the Scheme    ods.setCacheScheme (OracleConnectionCacheImpl.FIXED_RETURN_NULL_SCHEME);    Connection conn = null;    for (int i=0; i < 5; ++i )    {      conn = ods.getConnection();      if (conn != null)        System.out.println("Connection " + i + " Succeeded!");      else        System.out.println("Connection " + i + " Failed !!!");    }    System.out.println("Active size : " + ods.getActiveSize());    System.out.println("Cache Size is " + ods.getCacheSize());    // close the Data Source    ods.close();    System.out.println("Active size : " + ods.getActiveSize());    System.out.println("Cache Size is " + ods.getCacheSize());  }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -