📄 connectionwrappersample.java
字号:
/* * This sample shows how to list all the names from the EMP table * first using a normal connection and then a wrapped connectiion * and then a deeply nested wrapper */import java.sql.*;import oracle.jdbc.*;public class ConnectionWrapperSample{ public static void main (String args []) throws SQLException { DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); OracleConnection conn = (OracleConnection)(DriverManager.getConnection ("jdbc:oracle:oci8:@", "hr", "hr")); printEmployees( conn ); // Now wrap the connection OracleConnectionWrapper wrappedConnection = new OracleConnectionWrapper( conn ); printEmployees( wrappedConnection); // Wrap it in may layers for( int i=0; i<20; i++ ) wrappedConnection = new OracleConnectionWrapper( wrappedConnection ); printEmployees( wrappedConnection); conn.close(); }public static void printEmployees( oracle.jdbc.OracleConnection conn ) throws SQLException { Statement stmt = conn.createStatement (); ResultSet rset = stmt.executeQuery ("select LAST_NAME from EMPLOYEES"); while (rset.next ()) System.out.print(rset.getString(1) + " "); rset.close(); stmt.close(); System.out.println(); System.out.println(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -