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

82 lines
4.1 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="AS400JDBCRowSet class" />
<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="jdbcrowset" />
<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>AS400JDBCRowSet class</title>
</head>
<body id="jdbcrowset"><a name="jdbcrowset"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">AS400JDBCRowSet class</h1>
<div><p></p>
<div class="section"><p>The <a href="javadoc/com/ibm/as400/access/AS400JDBCRowSet.html#NAVBAR_TOP"> AS400JDBCRowSet</a> class represents a connected
rowset that encapsulates a JDBC result set. The methods on AS400JDBCRowSet
are very similar to those of the <a href="javadoc/com/ibm/as400/access/AS400JDBCResultSet.html#NAVBAR_TOP"> AS400JDBCResultSet</a>. The database connection
is maintained while in use.</p>
<p>You can use an instance of <a href="jdbcdatasource.htm#jdbcdatasource">AS400JDBCDataSource
or AS400JDBCConnectionPoolDataSource</a> to create the connection
to the database that you want to use to access the data for the AS400JDBCRowSet.</p>
</div>
<div class="section"><h4 class="sectiontitle">Examples</h4><p>The following examples show how you can
use the AS400JDBCRowSet class.</p>
<strong>Example: Creating, populating, and updating
an AS400JDBCRowSet object</strong> <pre> DriverManager.registerDriver(new AS400JDBCDriver());
// Establish connection by using a URL.
AS400JDBCRowSet rowset = new AS400JDBCRowSet("jdbc:as400://mySystem","myUser", "myPassword");
// Set the command used to populate the list.
rowset.setCommand("SELECT * FROM MYLIB.DATABASE");
// Populate the rowset.
rowset.execute();
// Update the customer balances.
while (rowset.next())
{
double newBalance = rowset.getDouble("BALANCE") +
july_statements.getPurchases(rowset.getString("CUSTNUM"));
rowset.updateDouble("BALANCE", newBalance);
rowset.updateRow();
}</pre>
<strong>Example: Creating and populating an AS400JDBCRowSet
object, while getting the data source from JNDI</strong> <pre> // Get the data source that is registered in JNDI (assumes JNDI environment is set).
Context context = new InitialContext();
AS400JDBCDataSource dataSource = (AS400JDBCDataSource) context.lookup("jdbc/customer");
AS400JDBCRowSet rowset = new AS400JDBCRowSet();
// Establish connection by setting the data source name.
rowset.setDataSourceName("jdbc/customer");
rowset.setUsername("myuser");
rowset.setPassword("myPasswd");
// Set the prepared statement and initialize the parameters.
rowset.setCommand("SELECT * FROM MYLIBRARY.MYTABLE WHERE STATE = ? AND BALANCE &gt; ?");
rowset.setString(1, "MINNESOTA");
rowset.setDouble(2, MAXIMUM_LIMIT);
// Populate the rowset.
rowset.execute();</pre>
</div>
</div>
</body>
</html>