import java.sql.SQLException; import java.sql.PreparedStatement; import java.sql.ResultSet; import oracle.jdbc.driver.OracleConnection; import oracle.jdbc.driver.OraclePreparedStatement; import sqlj.runtime.ref.DefaultContext; import oracle.sqlj.runtime.Oracle; /** Before executing this demo, or compiling this demo with online checking, you must run the SQL script PrefetchDemo.sql. This demo shows how to set different prefetch values for SQLJ SELECT statements. It compares SQLJ and JDBC runs. Additionally, when creating the data in the PREFETCH_DEMO table, we show how to batch INSERT statements in JDBC. Note that SQLJ currently does not support JDBC batching. However, it is always possible to interoperate with JDBC when it is necessary to exploit batching. **/ public class PrefetchDemo { #sql static iterator PrefetchDemoCur (int n); public static void main(String[] args) throws SQLException { System.out.println("*** Start of Prefetch demo ***"); Oracle.connect(PrefetchDemo.class,"connect.properties"); OracleConnection conn = (OracleConnection) DefaultContext.getDefaultContext().getConnection(); System.out.println("Connected."); try { #sql { DELETE FROM PREFETCH_DEMO }; } catch (SQLException exn) { System.out.println("A SQL exception occurred: "+exn); System.out.println("You probably forgot to run the PrefetchDemo.sql script"); System.out.println("Run the script and then try again."); System.exit(1); } System.out.println(">>> Inserting data into the PREFETCH_DEMO table <<<"); // We batch _all_ rows here, so there is only a single roundtrip. int numRows = 1000; insertRowsBatchedJDBC(numRows,conn); System.out.println(">>> Selecting data from the PREFETCH_DEMO table <<<"); System.out.println("Default Row Prefetch value is: " + conn.getDefaultRowPrefetch()); // We show four row prefetch settings: // 1. every row fetched individually // 2. prefetching the default number of rows (10) // 4. prefetching the default number of rows (10) // 3. prefetching all of the rows at once // // each setting is run with JDBC and with SQLJ int[] prefetch = new int[] { 1, conn.getDefaultRowPrefetch(), numRows / 10, numRows }; for (int i=0; i