ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaha_5.4.0.1/db2jdbcr.htm

173 lines
10 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="concept" />
<meta name="DC.Title" content="DB2JdbcRowSet" />
<meta name="abstract" content="The DB2JdbcRowSet is a connected RowSet, meaning that it can only be used with the support of an underlying Connection object, PreparedStatement object, or ResultSet object. Its implementation adheres closely to the description of a JdbcRowSet." />
<meta name="description" content="The DB2JdbcRowSet is a connected RowSet, meaning that it can only be used with the support of an underlying Connection object, PreparedStatement object, or ResultSet object. Its implementation adheres closely to the description of a JdbcRowSet." />
<meta name="DC.Relation" scheme="URI" content="rowsetty.htm" />
<meta name="DC.Relation" scheme="URI" content="rsetchar.htm" />
<meta name="DC.Relation" scheme="URI" content="db2cache.htm" />
<meta name="DC.Relation" scheme="URI" content="db2rowev.htm" />
<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="db2jdbcr" />
<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>DB2JdbcRowSet</title>
</head>
<body id="db2jdbcr"><a name="db2jdbcr"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">DB2JdbcRowSet</h1>
<div><p>The DB2JdbcRowSet is a connected RowSet, meaning that it can only
be used with the support of an underlying Connection object, PreparedStatement
object, or ResultSet object. Its implementation adheres closely to the description
of a JdbcRowSet.</p>
<div class="section"><h4 class="sectiontitle">Use DB2JdbcRowSet</h4><p>Because the DB2JdbcRowSet object
supports events described in the Java™ Database Connectivity (JDBC) 3.0 specification
for all RowSets, it can serve as an intermediate object between a local database
and other objects that must be notified about changes to the database data.</p>
<p>As
an example, assume that you are working in an environment where you have a
main database and several Personal Digital Assistants (PDAs) that use a wireless
protocol to connect to it. A DB2JdbcRowSet object can be used to move to a
row and update it by using a master application that is running on the server.
The row update causes an event to be generated by the RowSet component. If
there is a service running that is responsible for sending out updates to
the PDAs, it can register itself as a "listener" of the RowSet. Each time
that it receives a RowSet event, it can generate the appropriate update and
send it out to the wireless devices.</p>
<p>Refer to <a href="db2rowev.htm">Example:
DB2JdbcRowSet events</a> for more information.</p>
</div>
<div class="section"><h4 class="sectiontitle">Create JDBCRowSets</h4><p>There are several methods provided
for creating a DB2JDBCRowSet object. Each is outlined as follows.</p>
<strong>Use
DB2JdbcRowSet properties and DataSources</strong><p>DB2JdbcRowSets have properties
that accept an SQL query and a DataSource name. The DB2JdbcRowSets are then
ready to be used. The following is an example of this approach. The reference
to the DataSource named BaseDataSource is assumed to be a valid DataSource
that has been previously set up.</p>
<p><strong>Example:</strong> Use DB2JdbcRowSet
properties and DataSources</p>
<p><strong>Note:</strong> Read the <a href="codedisclaimer.htm">Code
example disclaimer</a> for important legal information.</p>
<pre> // Create a new DB2JdbcRowSet
DB2JdbcRowSet jrs = new DB2JdbcRowSet();
// Set the properties that are needed for
// the RowSet to be processed.
jrs.setDataSourceName("BaseDataSource");
jrs.setCommand("select col1 from cujosql.test_table");
// Call the RowSet execute method. This method causes
// the RowSet to use the DataSource and SQL query
// specified to prepare itself for data processing.
jrs.execute();
// Loop through the data in the RowSet.
while (jrs.next()) {
System.out.println("v1 is " + jrs.getString(1));
}
// Eventually, close the RowSet.
jrs.close();</pre>
<strong>Use DB2JdbcRowSet properties and JDBC URLs</strong><p>DB2JdbcRowSets
have properties that accept an SQL query and a JDBC URL. The DB2JdbcRowSets
are then ready to be used. The following is an example of this approach:</p>
<p><strong>Example:</strong> Use
DB2JdbcRowSet properties and JDBC URLs</p>
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code
example disclaimer</a> for important legal information.</div>
<pre> // Create a new DB2JdbcRowSet
DB2JdbcRowSet jrs = new DB2JdbcRowSet();
// Set the properties that are needed for
// the RowSet to be processed.
jrs.setUrl("jdbc:db2:*local");
jrs.setCommand("select col1 from cujosql.test_table");
// Call the RowSet execute method. This causes
// the RowSet to use the URL and SQL query specified
// previously to prepare itself for data processing.
jrs.execute();
// Loop through the data in the RowSet.
while (jrs.next()) {
System.out.println("v1 is " + jrs.getString(1));
}
// Eventually, close the RowSet.
jrs.close();</pre>
<strong>Use the setConnection(Connection) method to
use an existing database connection</strong><p>To promote the reuse of JDBC Connection
objects, the DB2JdbcRowSet allows you to pass an established connection to
the DB2JdbcRowSet. This connection is used by the DB2JdbcRowSet to prepare
itself for usage when the execute method is called.</p>
<p><strong>Example:</strong> Use
the setConnection method</p>
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code
example disclaimer</a> for important legal information.</div>
<pre> // Establish a JDBC Connection to the database.
Connection conn = DriverManager.getConnection("jdbc:db2:*local");
// Create a new DB2JdbcRowSet.
DB2JdbcRowSet jrs = new DB2JdbcRowSet();
// Set the properties that are needed for
// the RowSet to use an established connection.
jrs.setConnection(conn);
jrs.setCommand("select col1 from cujosql.test_table");
// Call the RowSet execute method. This causes
// the RowSet to use the connection that it was provided
// previously to prepare itself for data processing.
jrs.execute();
// Loop through the data in the RowSet.
while (jrs.next()) {
System.out.println("v1 is " + jrs.getString(1));
}
// Eventually, close the RowSet.
jrs.close();</pre>
</div>
<div class="section"><h4 class="sectiontitle">Access data and cursor movement</h4><p>Manipulation of
the cursor position and access to the database data through a DB2JdbcRowSet
are handled by the underlying ResultSet object. Tasks that can be done with
a ResultSet object also apply to the DB2JdbcRowSet object.</p>
</div>
<div class="section"><h4 class="sectiontitle">Change data and reflecting changes to the underlying database</h4><p>Support
for updating the database through a DB2JdbcRowSet is handled completely by
the underlying ResultSet object. Tasks that can be done with a ResultSet
object also apply to the DB2JdbcRowSet object. </p>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="db2rowev.htm">DB2JdbcRowSet events</a></strong><br />
All RowSet implementations support event handling for situations that are of interest to other components. This support allows application components to "talk" to each other when events happen to them. For example, updating a database row through a RowSet can cause a Graphical User Interface (GUI) table shown to you to update itself.</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rowsetty.htm" title="RowSets were originally added to the Java Database Connectivity (JDBC) 2.0 Optional Package. Unlike some of the better-known interfaces of the JDBC specification, the RowSet specification is designed to be more of a framework than an actual implementation. The RowSet interfaces define a set of core functionality that all RowSets have. RowSet implementation providers have considerable freedom to define the functionality that is needed to fit their needs in a specific problem space.">RowSets</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rsetchar.htm" title="You can request certain properties to be satisfied by the rowsets. Common properties include the set of interfaces to be supported by the resulting rowset.">RowSet characteristics</a></div>
<div><a href="db2cache.htm" title="The DB2CachedRowSet object is a disconnected RowSet, meaning that it can be used without being connected to the database. Its implementation adheres closely to the description of a CachedRowSet. The DB2CachedRowSet is a container for rows of data from a ResultSet. The DB2CachedRowSet holds all its own data so it does not need to maintain a connection to the database other than explicitly while reading or writing data to the database.">DB2CachedRowSet</a></div>
</div>
</div>
</body>
</html>