ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/microjdbcmelivers.htm

217 lines
13 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Result sets" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="microjdbcmelivers" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Result sets</title>
</head>
<body id="microjdbcmelivers"><a name="microjdbcmelivers"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Result sets</h1>
<div><p></p>
<div class="section"><p>The ToolboxME for iSeries™ result set classes are:</p>
<ul><li> <a href="#microjdbcmelivers__jdbcmeliveresultset">JdbcMeLiveResultSet</a></li>
<li> <a href="#microjdbcmelivers__offline">JdbcMeOfflineResultSet</a></li>
<li> <a href="#microjdbcmelivers__jdbcresultsetmeta">JdbcMeResultSetMetaData</a></li>
</ul>
<p>JdbcMeLiveResultSet and JdbcMeOfflineResultSet contain the same functionality,
except that:</p>
<ul><li>JdbcMeLiveResultSet retrieves data by making a call to the database on
the server</li>
<li>JdbcMeOfflineResultSet retrieves data from the database on the local device </li>
</ul>
<div class="note"><span class="notetitle">Note:</span> To use ToolboxMe for iSeries classes, you must separately
download and set up the ToolboxME for iSeries component. For more information,
see <a href="microsetup.htm#microsetup">Downloading and setting up ToolboxME
for iSeries</a>.</div>
</div>
<div class="section" id="microjdbcmelivers__jdbcmeliveresultset"><a name="microjdbcmelivers__jdbcmeliveresultset"><!-- --></a><h4 class="sectiontitle">JdbcMeLiveResultSet</h4><p>The <a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#NAVBAR_TOP">JdbcMeLiveResultSet class</a> provides a subset of functions
available in the IBM<sup>®</sup> Toolbox for Java™ <a href="javadoc/com/ibm/as400/access/AS400JDBCResultSet.html">AS400JDBCResultSet class</a>. Use JdbcMeLiveResultSet in
your Tier0 client application to access a table of data that is generated
by running a query.</p>
<p>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:</p>
<ul><li><a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#GETSTRING(INT)">Retrieve data</a> of various types that are stored in the
result set</li>
<li> Move the cursor to the row you specify (previous row, current row, next
row, and so on)</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#INSERTROW()">Insert</a>, <a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#UPDATEROW()">update</a>, and <a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#DELETEROW()">delete</a> rows</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#UPDATEINT(INT, INT)">Update columns</a> (using String and int values)</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#GETMETADATA()">Retrieve the ResultSetMetaData object</a> that describes
the columns in the result set</li>
</ul>
<p id="microjdbcmelivers__curmovme"><a name="microjdbcmelivers__curmovme"><!-- --></a>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:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" frame="border" border="1" rules="all"><thead align="left"><tr class="tablemainheaderbar"><th valign="top" width="100%" id="d0e104">Scrollable cursor positions</th>
</tr>
</thead>
<tbody><tr><td valign="top" width="100%" headers="d0e104 "><p><a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#ABSOLUTE(INT)">absolute</a> <br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#FIRST()">first</a><br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#LAST()">last</a><br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#MOVETOCURRENTROW()"> moveToCurrentRow</a><br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#MOVETOINSERTROW()">moveToInsertRow</a> <br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#PREVIOUS()">previous</a><br />
<a href="javadoc/com/ibm/as400/micro/JdbcMeLiveResultSet.html#RELATIVE(INT)">relative</a></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="microjdbcmelivers__scrollme"><a name="microjdbcmelivers__scrollme"><!-- --></a><h4 class="sectiontitle">Scrolling capabilities</h4><p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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. </p>
</div>
<div class="section" id="microjdbcmelivers__concurme"><a name="microjdbcmelivers__concurme"><!-- --></a><h4 class="sectiontitle">Updatable result sets</h4><p>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.</p>
<p>See <a href="javadoc/com/ibm/as400/access/AS400JDBCResultSet.html#METHOD_SUMMARY"> Method Summary</a> for a complete listing of the update
methods available in JdbcMeResultSet.</p>
</div>
<div class="section"><p id="microjdbcmelivers__updexme"><a name="microjdbcmelivers__updexme"><!-- --></a><strong>Example: Updatable result sets</strong></p>
<p>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).</p>
<pre> // 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();</pre>
</div>
<div class="section" id="microjdbcmelivers__offline"><a name="microjdbcmelivers__offline"><!-- --></a><h4 class="sectiontitle">JdbcMeOfflineResultSet class</h4><p>The <a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#NAVBAR_TOP">JdbcMeOfflineResultSet class</a> provides a subset of functions
available in the IBM Toolbox for Java <a href="javadoc/com/ibm/as400/access/AS400JDBCResultSet.html">AS400JDBCResultSet class</a>. Use JdbcMeOfflineResultSet
in in your <a href="microconcept.htm#microconcept__tier0">Tier0</a>
client application to access a table of data that is generated by running
a query.</p>
<p>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.</p>
<p>JdbcMeOfflineResultSet includes methods
that enable you to perform the following actions:</p>
<ul><li><a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#GETSTRING(INT)">Retrieve data</a> of various types that are stored in the
result set</li>
<li> Move the cursor to the row you specify (previous row, current row, next
row, and so on)</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#INSERTROW()">Insert</a>, <a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#UPDATEROW()">update</a>, and <a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#DELETEROW()">delete</a> rows</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#UPDATESTRING(INT, JAVA.LANG.STRING)">Update columns</a> (using String and int values)</li>
<li><a href="javadoc/com/ibm/as400/micro/JdbcMeOfflineResultSet.html#GETMETADATA()">Retrieve the ResultSetMetaData object</a> that describes
the columns in the result set</li>
</ul>
<p>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. </p>
</div>
<div class="section" id="microjdbcmelivers__jdbcresultsetmeta"><a name="microjdbcmelivers__jdbcresultsetmeta"><!-- --></a><h4 class="sectiontitle">JdbcMeResultSetMetaData class</h4><p>The <a href="javadoc/com/ibm/as400/micro/JdbcMeResultSetMetaData.html#NAVBAR_TOP">JdbcMeResultSetMetaData class</a> provides a subset of functions
available in the IBM Toolbox for Java <a href="javadoc/com/ibm/as400/access/AS400JDBCResultSetMetaData.html">AS400JDBCResultSetMetaData class</a>. Use JdbcMeResultSetMetaData
in your Tier0 client application to determine the types and properties of
the columns in a JdbcMeLiveResultSet or JdbcMeOfflineResultSet.</p>
<p>The
following example shows how to use the JdbcMeResultSetMetaData class:</p>
<pre> // 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();</pre>
</div>
</div>
</body>
</html>