com.ibm.as400.util.servlet
Class SQLResultSetRowData

java.lang.Object
  |
  +--com.ibm.as400.util.servlet.RowData
        |
        +--com.ibm.as400.util.servlet.SQLResultSetRowData

public class SQLResultSetRowData
extends RowData

The SQLResultSetRowData class represents an SQL ResultSet as a list of data. The ResultSet object is generated by an executed SQL statement.

An SQLResultSetRowData object maintains a position in the list that points to its current row of data. The initial position in the list is set before the first row. The next method moves to the next row in the list.

The getObject method is used to retrieve the column value for the current row indexed by the column number. Columns are numbered starting from 0.

The number, types, and properties of the list's columns are provided by the SQLResultSetMetaData object returned by the getMetaData method.

The following example creates an SQLResultSetRowData object and initializes it to an SQL ResultSet.

// Register and get a connection to the database. DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver()); Connection connection = DriverManager.getConnection("jdbc:as400://mySystem");

// Execute an SQL statement and get the result set. Statement statement = connection.createStatement(); statement.execute("select * from qiws.qcustcdt"); ResultSet resultSet = statement.getResultSet();

// Create the SQLResultSetRowData object and initialize to the result set. SQLResultSetRowData rowData = new SQLResultSetRowData(resultSet);

See Also:
Serialized Form

Constructor Summary
SQLResultSetRowData()
          Constructs a default SQLResultSetRowData object.
SQLResultSetRowData(java.sql.ResultSet resultSet)
          Constructs a SQLResultSetRowData object with the specified resultSet.
 
Method Summary
 boolean absolute(int rowIndex)
          Sets the position to the specified rowIndex.
 void afterLast()
          Sets the position after the last row in the list.
 void beforeFirst()
          Sets the position before the first row in the list.
 void close()
          Closes the SQL result set.
 boolean first()
          Sets the position to the first row in the list.
 int getCurrentPosition()
          Returns the current row position.
 RowMetaData getMetaData()
          Returns the metadata.
 java.lang.Object getObject(int columnIndex)
          Returns the current row's column data specified at columnIndex.
 java.util.Vector getObjectProperties(int columnIndex)
          Returns the current row's property list for the specified columnIndex.
 java.sql.ResultSet getResultSet()
          Returns the SQL result set.
 java.util.Vector[] getRowProperties()
          Returns the current row's property list.
 boolean isAfterLast()
          Indicates whether the current position is after the last row in the list.
 boolean isBeforeFirst()
          Indicates whether the current position is before the first row in the list.
 boolean isFirst()
          Indicates whether the current position is the first row in the list.
 boolean isLast()
          Indicates whether the current position is the last row in the list.
 boolean last()
          Sets the position to the last row in the list.
 int length()
          Returns the length of the result list.
 boolean next()
          Sets the position to the next row in the list.
 boolean previous()
          Sets the position to the previous row in the list.
 boolean relative(int numberOfRows)
          Sets the position a relative numberOfRows based on the current position.
 void setObjectProperties(java.util.Vector properties, int columnIndex)
          Sets the column object's properties at the specified columnIndex.
 void setResultSet(java.sql.ResultSet resultSet)
          Sets the SQL result set.
 
Methods inherited from class com.ibm.as400.util.servlet.RowData
addPropertyChangeListener, addVetoableChangeListener, removePropertyChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLResultSetRowData

public SQLResultSetRowData()
Constructs a default SQLResultSetRowData object.

SQLResultSetRowData

public SQLResultSetRowData(java.sql.ResultSet resultSet)
                    throws RowDataException
Constructs a SQLResultSetRowData object with the specified resultSet. The remaining rows are read from the ResultSet starting at the current cursor position. The ResultSet is left in an open state with the cursor positioned after the last row. The ResultSet can be closed using the close method.
Parameters:
resultSet - The SQL result set. An empty result set is invalid.
Throws:
RowDataException - If the cursor state of the result set is invalid or a rowdata error occurs.
See Also:
close()
Method Detail

absolute

public boolean absolute(int rowIndex)
Sets the position to the specified rowIndex. Attempting to move beyond the first row will move to the position before the first row. Attempting to move beyond the last row will move to the position after the last row.
Overrides:
absolute in class RowData
Parameters:
rowIndex - The row index (0-based). The rowIndex must be zero or a positive integer which is less than the number of rows.
Returns:
true if the requested position exists; false otherwise.

afterLast

public void afterLast()
Sets the position after the last row in the list. This is a valid position after the end of the list.
Overrides:
afterLast in class RowData

beforeFirst

public void beforeFirst()
Sets the position before the first row in the list. This is a valid position before the beginning of the list.
Overrides:
beforeFirst in class RowData

close

public void close()
           throws RowDataException
Closes the SQL result set.
Throws:
RowDataException - If a row data error occurs.

first

public boolean first()
Sets the position to the first row in the list.
Overrides:
first in class RowData
Returns:
true if the requested position exists; false otherwise.

getCurrentPosition

public int getCurrentPosition()
Returns the current row position.
Overrides:
getCurrentPosition in class RowData
Returns:
The row position (0-based).

getMetaData

public RowMetaData getMetaData()
                        throws RowDataException
Returns the metadata.
Overrides:
getMetaData in class RowData
Returns:
The metadata.
Throws:
RowDataException - If a row data error occurs.

getObject

public java.lang.Object getObject(int columnIndex)
                           throws RowDataException
Returns the current row's column data specified at columnIndex.
Overrides:
getObject in class RowData
Parameters:
columnIndex - The column index (0-based).
Returns:
The column object.
Throws:
RowDataException - If a row data error occurs.

getObjectProperties

public java.util.Vector getObjectProperties(int columnIndex)
Returns the current row's property list for the specified columnIndex.
Overrides:
getObjectProperties in class RowData
Parameters:
columnIndex - The column index (0-based).
Returns:
The property list for the column data object.

getRowProperties

public java.util.Vector[] getRowProperties()
Returns the current row's property list.
Overrides:
getRowProperties in class RowData
Returns:
The property lists for each data object in the row.

getResultSet

public java.sql.ResultSet getResultSet()
Returns the SQL result set. Null is returned if the object was serialized. The result set data is cached during serialization.
Returns:
The SQL result set.

isAfterLast

public boolean isAfterLast()
Indicates whether the current position is after the last row in the list. This is a valid position after the end of the list.
Overrides:
isAfterLast in class RowData
Returns:
true if the position is after the last row; false otherwise.

isBeforeFirst

public boolean isBeforeFirst()
Indicates whether the current position is before the first row in the list. This is a valid position before the beginning of the list.
Overrides:
isBeforeFirst in class RowData
Returns:
true if the position is before the first row; false otherwise.

isFirst

public boolean isFirst()
Indicates whether the current position is the first row in the list.
Overrides:
isFirst in class RowData
Returns:
true if the position is the first row; false otherwise.

isLast

public boolean isLast()
Indicates whether the current position is the last row in the list.
Overrides:
isLast in class RowData
Returns:
true if the position is the last row; false otherwise.

last

public boolean last()
Sets the position to the last row in the list.
Overrides:
last in class RowData
Returns:
true if the requested position exists; false otherwise.

length

public int length()
Returns the length of the result list.
Overrides:
length in class RowData
Returns:
The length.

next

public boolean next()
Sets the position to the next row in the list. The list is initially positioned before its first row. The first call to next makes the first row the current row, the second call makes the second row the current row, etc. Moving beyond last row in the list will result in a position after the last row.
Overrides:
next in class RowData
Returns:
true if the requested position exists in the list; false if there are no more rows.

previous

public boolean previous()
Sets the position to the previous row in the list. Moving beyond the first row in the list will result in a position before the first row.
Overrides:
previous in class RowData
Returns:
true if the requested position exists in the list; false otherwise.

relative

public boolean relative(int numberOfRows)
Sets the position a relative numberOfRows based on the current position. Moving beyond the first/last row in the list will result in a position before/after the first/last row.
Overrides:
relative in class RowData
Parameters:
numberOfRows - The number of rows to move, either positive or negative.
Returns:
true if the requested position exists; false otherwise.

setObjectProperties

public void setObjectProperties(java.util.Vector properties,
                                int columnIndex)
Sets the column object's properties at the specified columnIndex.
Overrides:
setObjectProperties in class RowData
Parameters:
properties - The properties.
columnIndex - The column index (0-based).

setResultSet

public void setResultSet(java.sql.ResultSet resultSet)
                  throws RowDataException,
                         java.beans.PropertyVetoException
Sets the SQL result set. The remaining rows are read from the ResultSet starting at the current cursor position. The ResultSet is left in an open state with the cursor positioned after the last row. The ResultSet can be closed using the close method. If a result set already exists, then setting the result set will remove all rows from the list before reading in the new data.
Parameters:
resultSet - The SQL result set. An empty result set is invalid.
Throws:
RowDataException - If the cursor state of the result set is invalid or a rowdata error occurs.
java.beans.PropertyVetoException - If a change is vetoed.
See Also:
close()