Result sets

The ToolboxME for iSeries™ result set classes are:

JdbcMeLiveResultSet and JdbcMeOfflineResultSet contain the same functionality, except that:

Note: To use ToolboxMe for iSeries classes, you must separately download and set up the ToolboxME for iSeries component. For more information, see Downloading and setting up ToolboxME for iSeries.

JdbcMeLiveResultSet

The JdbcMeLiveResultSet class provides a subset of functions available in the IBM® Toolbox for Java™ AS400JDBCResultSet class. Use JdbcMeLiveResultSet in your Tier0 client application to access a table of data that is generated by running a query.

JdbcMeLiveResultSet retrieves the table rows in sequence. Within a row, you can access column values in any order. JdbcMeLiveResultSet includes methods that enable you to perform the following actions:

A cursor, which is an internal pointer, is used by a result set to point the row in the result set that is being accessed by the Java program. JDBC 2.0 provides additional methods for accessing specific positions within a database:

Scrolling capabilities

If a result set is created by executing a statement, you can move (scroll) backward (last-to-first) or forward (first-to-last) through the rows in a table.

A result set that supports this movement is called a scrollable result set. Scrollable result sets also support relative and absolute positioning. Relative positioning allows you to move to a row in the result set by specifying a position that is relative to the current row. Absolute positioning allows you to move directly to a row by specifying its position in the result set.

With JDBC 2.0, you have two additional scrolling capabilities available to use when working with the ResultSet class: scroll-insensitive and scroll-sensitive result sets.

A scroll-insensitive result set is not typically sensitive to changes that are made while it is open, while the scroll-sensitive result set is sensitive to changes. The IBM Toolbox for Java JDBC driver does not support scroll-insensitive result sets.

Updatable result sets

In your application, you can use result sets that use either read-only concurrency (no updates can be made to the data) or updatable concurrency (allows updates to the data and may use database write locks to control access to the same data item by different transactions). In an updatable result set, rows can be updated, inserted, and deleted.

See Method Summary for a complete listing of the update methods available in JdbcMeResultSet.

Example: Updatable result sets

The following example shows how to use a result set that allows updates to the data (update concurrency) and allows changes to be made to the result set while it is open (scroll sensitive).

          // Connect to the server.
     Connection c = JdbcMeDriver.getConnection(
        "jdbc:as400://mySystem;meserver=myMeServer;user=auser;password=apassword");

          // Create a Statement object.  Set the result set
          // concurrency to updatable.
     Statement s = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

          // Run a query. The result is placed
          // in a ResultSet object.
     ResultSet rs = s.executeQuery ("SELECT NAME,ID FROM MYLIBRARY.MYTABLE FOR UPDATE");

          // Iterate through the rows of the ResultSet. As we read
          // the row, we will update it with a new ID.
     int newId = 0;
     while (rs.next ())
     {

              // Get the values from the ResultSet. The first value
              // is a string, and the second value is an integer.
         String name = rs.getString("NAME");
         int id = rs.getInt("ID");

         System.out.println("Name = " + name);
         System.out.println("Old id = " + id);

              // Update the id with a new integer.
         rs.updateInt("ID", ++newId);
        
              // Send the updates to the server.
         rs.updateRow ();

         System.out.println("New id = " + newId);
     }

          // Close the Statement and the Connection.
     s.close();
     c.close();

JdbcMeOfflineResultSet class

The JdbcMeOfflineResultSet class provides a subset of functions available in the IBM Toolbox for Java AS400JDBCResultSet class. Use JdbcMeOfflineResultSet in in your Tier0 client application to access a table of data that is generated by running a query.

Use the JdbcMeOfflineResultSet class to work with data that resides on your Tier0 device. The data that resides on the device might already reside there or you might have put it there by calling JdbcMeStatement.executeToOfflineData() method. the executeToOfflineData() method downloads and stores to the device all of the data that satisfies the query. You can then use JdbcMeOfflineResultSet class to access the stored data.

JdbcMeOfflineResultSet includes methods that enable you to perform the following actions:

You can provide the ability to synchronize the local device database with the database on the iSeries server by using the functions present in the JdbcMe classes.

JdbcMeResultSetMetaData class

The JdbcMeResultSetMetaData class provides a subset of functions available in the IBM Toolbox for Java AS400JDBCResultSetMetaData class. Use JdbcMeResultSetMetaData in your Tier0 client application to determine the types and properties of the columns in a JdbcMeLiveResultSet or JdbcMeOfflineResultSet.

The following example shows how to use the JdbcMeResultSetMetaData class:

          // Connect to the server.
     Connection c = JdbcMeDriver.getConnection(
        "jdbc:as400://mySystem;meserver=myMeServer;user=auser;password=apassword");

          // Create a Statement object.
     Statement s = c.createStatement();

          // Run a query. The result is placed in a ResultSet object.
     JdbcMeLiveResultSet rs = s.executeQuery ("SELECT NAME,ID FROM MYLIBRARY.MYTABLE");

          // Iterate through the rows of the ResultSet.
     while (rs.next ())
     {

              // Get the values from the ResultSet. The first value is
              // a string, and the second value is an integer.
         String name = rs.getString("NAME");
         int id = rs.getInt("ID");

         System.out.println("Name = " + name);
         System.out.println("ID = " + id);
     }

          // Close the Statement and the Connection.
     s.close();
     c.close();