?? ccache2.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 + -