rowprefetch_statement.java

来自「比较实用的C++编程思想 有很多例子可以用」· Java 代码 · 共 64 行

JAVA
64
字号
/* * 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 individual * statements. * */// You need to import the java.sql package to use JDBCimport java.sql.*;// You need to import oracle.jdbc.driver in order to use the// Oracle extensionsimport oracle.jdbc.driver.*;class RowPrefetch_statement{  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");    // get the value of the default row prefetch from the connection object    int default_row_prefetch =      ((OracleConnection)conn).getDefaultRowPrefetch ();    System.out.println ("The Default RowPrefetch for the connection is: "			+ default_row_prefetch);    Statement stmt = conn.createStatement ();    // set the RowPrefetch value from the statement object    // This sets the rowPrefetch only for this particular statement.    // All other statements will use the default RowPrefetch from the    // connection.    ((OracleStatement)stmt).setRowPrefetch (30);        // 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 ();    stmt.close ();  }}

⌨️ 快捷键说明

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