Each result set is described by its meta data. To get meta data for a result
set, we use the getMetaData() method for the result set. For example:
ResultSetMetaData rsmd=rs.getMetaData();
We can illustrate this best with some sample code. For the following
example code, we assume the connection
has been created (see ,
 Creating the DB2 connection  on page 84) and an output stream
a. First, we create the statement:
b. Next, we execute the statement of type query, with a return result of
type ResultSet:
ResultSet rs=stmt.executeQuery( select * from userinfo );
c. To print out the first column of each result set row, we have the
following code snippet:
while (rs.next()) {
d. To get even more fancy, we can print out all of columns of each result
set row by obtaining the result set meta data, determining how many
columns are in the result set, and then printing out each column with
the getString method:
int numFields=rsmd.getColumnCount();
while (rs.next()) {
for (int currentField=1; i<=numFields; currField++) {
// next row
Fields/Columns start at 1
Note that the field/column count starts at 1. Hence, the for loop in the
preceding sample code starts looping from 1.
The getString method can be used with a column number as we have
done or with a column name, for example:
rs.getString( first_name )
You will see this method used in both forms in later examples.
Linux Web Hosting with WebSphere, DB2, and Domino



About Services Network Support FAQ Order Contact

Linux Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved