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

101 lines
7.3 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?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="Retrieve ResultSet data" />
<meta name="abstract" content="The ResultSet object provides several methods for obtaining column data for a row. All are of the form get&lt;Type&gt;, where &lt;Type&gt; is a Java data type. Some examples of these methods include getInt, getLong, getString, getTimestamp, and getBlob. Nearly all of these methods take a single parameter that is either the column index within the ResultSet or the column name." />
<meta name="description" content="The ResultSet object provides several methods for obtaining column data for a row. All are of the form get&lt;Type&gt;, where &lt;Type&gt; is a Java data type. Some examples of these methods include getInt, getLong, getString, getTimestamp, and getBlob. Nearly all of these methods take a single parameter that is either the column index within the ResultSet or the column name." />
<meta name="DC.Relation" scheme="URI" content="rsltsets.htm" />
<meta name="DC.Relation" scheme="URI" content="rsltchar.htm" />
<meta name="DC.Relation" scheme="URI" content="rsltcurs.htm" />
<meta name="DC.Relation" scheme="URI" content="rsltchng.htm" />
<meta name="DC.Relation" scheme="URI" content="rsltclse.htm" />
<meta name="DC.Relation" scheme="URI" content="resultex.htm" />
<meta name="DC.Relation" scheme="URI" content="rsmd.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="rsltdata" />
<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>Retrieve ResultSet data</title>
</head>
<body id="rsltdata"><a name="rsltdata"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Retrieve ResultSet data</h1>
<div><p>The ResultSet object provides several methods for obtaining column
data for a row. All are of the form get&lt;<em>Type</em>&gt;, where &lt;<em>Type</em>&gt;
is a Java™ data
type. Some examples of these methods include getInt, getLong, getString, getTimestamp,
and getBlob. Nearly all of these methods take a single parameter that is either
the column index within the ResultSet or the column name.</p>
<p>ResultSet columns are numbered, starting with 1. If the column name is
used and there is more than one column in the ResultSet with the same name,
the first one is returned. There are some get&lt;Type&gt; methods that have
additional parameters, such as the optional Calendar object, which can be
passed to getTime, getDate, and getTimestamp. Refer to the Javadoc for the <a href="javaapi/api/java/sql/package-summary.html" target="_blank">java.sql
package</a> for full details.</p>
<p>For get methods that return objects, the return value is null when the
column in the ResultSet is null. For primitive types, null cannot be returned.
In these cases, the value is 0 or false. If an application must distinguish
between null, and 0 or false, the wasNull method can be used immediately after
the call. This method can then determine whether the value was an actual 0
or false value, or if that value was returned because the ResultSet value
was indeed null.</p>
<p>See <a href="resultex.htm">Example: ResultSet interface for IBM<sup>®</sup> Developer
Kit for Java</a> for an example on how to use the ResultSet
interface.</p>
<div class="section"><h4 class="sectiontitle">ResultSetMetaData support</h4><p>When the getMetaData method
is called on a ResultSet object, the method returns a ResultSetMetaData object
describing the columns of that ResultSet object. When the SQL statement being
processed is unknown until runtime, the ResultSetMetaData can be used to determine
what get methods should be used to retrieve the data. The following code example
uses ResultSetMetaData to determine each column type in the result set:</p>
<p><strong>Example:</strong> Use
ResultSetMetaData to determine each column type in a result set</p>
<p><strong>Note:</strong> Read
the <a href="codedisclaimer.htm">Code example disclaimer</a> for important
legal information.</p>
<pre>ResultSet rs = stmt.executeQuery(sqlString);
ResultSetMetaData rsmd = rs.getMetaData();
int colType [] = new int[rsmd.getColumnCount()];
for (int idx = 0, int col = 1; idx &lt; colType.length; idx++, col++)
colType[idx] = rsmd.getColumnType(col);</pre>
<p>See <a href="rsmd.htm#rsmd">Example: ResultSetMetaData interface for IBM Developer Kit for Java</a> for
an example of how to use the ResultSetMetaData interface. </p>
</div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><strong><a href="rsmd.htm">Example: ResultSetMetaData interface for IBM Developer Kit for Java</a></strong><br />
</li>
</ul>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rsltsets.htm" title="The ResultSet interface provides access to the results generated by running queries. Conceptually, data of a ResultSet can be thought of as a table with a specific number of columns and a specific number of rows. By default, the table rows are retrieved in sequence. Within a row, column values can be accessed in any order.">ResultSets</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rsltchar.htm" title="This topic discusses ResultSet characteristics such ResultSet types, concurrency, ability to close the ResultSet by committing the connection object, and specification of ResultSet characteristics.">ResultSet characteristics</a></div>
<div><a href="rsltcurs.htm" title="The iSeries Java Database Connectivity (JDBC) drivers support scrollable ResultSets. With a scrollable ResultSet, you can process rows of data in any order using a number of cursor-positioning methods.">Cursor movement</a></div>
<div><a href="rsltclse.htm" title="To create a ResultSet object, you can use executeQuery methods, or other methods. This article describes options for creating ResultSets.">Create ResultSets</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="rsltchng.htm" title="With the iSeries JDBC drivers, you can change ResultSets by performing several tasks.">Change ResultSets</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="resultex.htm" title="This is an example of how to use the ResultSet interface.">Example: ResultSet interface for IBM Developer Kit for Java</a></div>
</div>
</div>
</body>
</html>