📄 rowprefetch_connection.java
字号:
/* * This sample shows how to use the Oracle performance extensions * for row-prefetching. This allows the driver to fetch multiple * rows in one round-trip, saving unecessary round-trips to the database. * * This example shows how to set the rowPrefetch for the connection object, * which will be used for all statements created from this connection. * Please see RowPrefetch_statement.java for examples of how to set * the rowPrefetch for statements individually. * */// You need to import the java.sql package to use JDBCimport java.sql.*;// You need to import oacle.jdbc.driver in order to use the oracle extensions.import oracle.jdbc.driver.*;class RowPrefetch_connection{ public static void main (String args []) throws SQLException { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // set the RowPrefetch value from the Connection object // This sets the rowPrefetch for *all* statements belonging // to this connection. // The rowPrefetch value can be overriden for specific statements by // using the setRowPrefetch API on the statement object. Please look // at RowPrefetch_statement.java for an example. // Please note that any statements created *before* the connection // rowPrefetch was set, will use the default rowPrefetch. ((OracleConnection)conn).setDefaultRowPrefetch (30); Statement stmt = conn.createStatement (); // Check to verify statement rowPrefetch value is 30. int row_prefetch = ((OracleStatement)stmt).getRowPrefetch (); System.out.println ("The RowPrefetch for the statement is: " + row_prefetch + "\n"); ResultSet rset = stmt.executeQuery ("select ename from emp"); while(rset.next ()) { System.out.println (rset.getString (1)); } rset.close (); stmt.close (); conn.close (); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -