📄 ccache1.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 DYNAMIC_SCHEME of OracleConnectionCacheImpl. * Dynamic Scheme : This is the default scheme. New connections could be * created beyond the Max limit upon request but closed and freed when the * logical connections are closed. When all the connections are active and * busy, requests for new connections willend up creating new physical * connections. But these physical connections are closed when the * corresponding logical connections are closed. A typical grow and shrink * scheme. * Please compare with CCache2.java and CCache3.java * * Please use jdk1.2 or later version */import java.sql.*;import javax.sql.*;import oracle.jdbc.*;import oracle.jdbc.pool.*;class CCache1{ public static void main (String args []) throws SQLException { OracleConnectionCacheImpl ods = new OracleConnectionCacheImpl(); 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 } ods.setURL(url); ods.setUser("hr"); ods.setPassword("hr"); // Set the Max Limit ods.setMaxLimit (3); Connection conn1 = null; conn1 = ods.getConnection(); if (conn1 != null) System.out.println("Connection 1 " + " Succeeded!"); else System.out.println("Connection 1 " + " Failed !!!"); Connection conn2 = null; conn2 = ods.getConnection(); if (conn2 != null) System.out.println("Connection 2 " + " Succeeded!"); else System.out.println("Connection 2 " + " Failed !!!"); Connection conn3 = null; conn3 = ods.getConnection(); if (conn3 != null) System.out.println("Connection 3 " + " Succeeded!"); else System.out.println("Connection 3 " + " Failed !!!"); Connection conn4 = null; conn4 = ods.getConnection(); if (conn4 != null) System.out.println("Connection 4 " + " Succeeded!"); else System.out.println("Connection 4 " + " Failed !!!"); Connection conn5 = null; conn5 = ods.getConnection(); if (conn5 != null) System.out.println("Connection 5 " + " Succeeded!"); else System.out.println("Connection 5 " + " Failed !!!"); System.out.println("Active size : " + ods.getActiveSize()); System.out.println("Cache Size is " + ods.getCacheSize()); // Close 3 logical Connections conn1.close(); conn2.close(); conn3.close(); 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 + -