All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.ibm.as400.vaccess.SQLResultSetFormPane

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----javax.swing.JComponent
                           |
                           +----com.ibm.as400.vaccess.SQLResultSetFormPane

public class SQLResultSetFormPane
extends JComponent
implements Serializable
The SQLResultSetFormPane class represents a form that is filled in with the result set generated by a SQL query using JDBC. The form displays one record of the result set at a time and provides buttons that allow the user to scroll forward, backward, to the first or last record, or refresh the view of the result set.

The data in the form is retrieved from the system (and the GUI fields for the data are created) when load() is called. If load() is not called, the form will be empty.

It is up to the user to register a JDBC driver when using this class. For example, the following code registers the AS/400 Toolbox for Java JDBC driver.

DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());

Users should call close() to ensure that the result set is closed when this table is no longer needed. close() should also be called on the SQLConnection object as well to close the connection.

Most errors are reported by firing ErrorEvents, rather than throwing exceptions. Users should listen for ErrorEvents in order to diagnose and recover from error conditions.

SQLResultSetFormPane objects generate the following events:

// Register JDBC driver.
DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());
// Set up table for result set contents.
final SQLConnection connection = new SQLConnection("MySystem", "Userid", "Password");
String query = "SELECT * FROM MYLIB.MYTABLE";
final SQLResultSetFormPane pane = new SQLResultSetFormPane(connection, query);
// Set up window to hold table
JFrame frame = new JFrame ("My Window");
WindowListener l = new WindowAdapter()
{
// Close the pane when window is closed.
public void windowClosing(WindowEvent e)
{
pane.close();
connection.close();
}
};
frame.addWindowListener(l);
// Set up the error dialog adapter.
pane.addErrorListener (new ErrorDialogAdapter (frame));
// Add the component and get data from system.
frame.getContentPane().add(pane);
pane.load();
// Display the window
frame.setVisible(true)


Constructor Index

 o SQLResultSetFormPane()
Constructs a SQLResultSetFormPane object.
 o SQLResultSetFormPane(SQLConnection, String)
Constructs a SQLResultSetFormPane object.

Method Index

 o addActionCompletedListener(ActionCompletedListener)
Adds a listener to be notified when a new record is displayed.
 o addErrorListener(ErrorListener)
Adds a listener to be notified when an error occurs.
 o clearWarnings()
Clears all SQL warnings.
 o close()
Closes the SQL result set this form represents.
 o displayFirst()
Displays the first record of the result set.
 o displayLast()
Displays the last record of the result set.
 o displayNext()
Displays the next record of the result set.
 o displayPrevious()
Displays the previous record of the result set.
 o getConnection()
Returns the SQL connection with which to access data.
 o getCurrentRecord()
Returns the index of the record currently being displayed.
 o getLabelText(int)
Returns the text of the label at the given index.
 o getQuery()
Returns the SQL query used to generate the form data.
 o getStringValueAt(int)
Returns the string value of the current record at the given index.
 o getValueAt(int)
Returns the value of the current record at the given index.
 o getWarnings()
Returns the warnings generated by the JDBC connection, statement, and result set.
 o load()
Refreshes the view based on the state of the system.
 o removeActionCompletedListener(ActionCompletedListener)
Removes a listener from being notified when a new record is displayed.
 o removeErrorListener(ErrorListener)
Removes a listener from being notified when an error occurs.
 o setConnection(SQLConnection)
Sets the SQL connection with which to access data.
 o setLabelText(int, String)
Sets the text of the label at the given index.
 o setQuery(String)
Sets the SQL query used to generate the result set.

Constructors

 o SQLResultSetFormPane
 public SQLResultSetFormPane()
Constructs a SQLResultSetFormPane object.

 o SQLResultSetFormPane
 public SQLResultSetFormPane(SQLConnection connection,
                             String query)
Constructs a SQLResultSetFormPane object.

Parameters:
connection - The SQL connection.
query - The SQL query.

Methods

 o addActionCompletedListener
 public void addActionCompletedListener(ActionCompletedListener listener)
Adds a listener to be notified when a new record is displayed. The listener's actionCompleted() method will be called.

Parameters:
listener - The listener.
 o addErrorListener
 public void addErrorListener(ErrorListener listener)
Adds a listener to be notified when an error occurs. The listener's errorOccurred() method will be called.

Parameters:
listener - The listener.
 o clearWarnings
 public void clearWarnings()
Clears all SQL warnings.

 o close
 public void close()
Closes the SQL result set this form represents.

 o displayFirst
 public void displayFirst()
Displays the first record of the result set.

 o displayLast
 public void displayLast()
Displays the last record of the result set.

 o displayNext
 public void displayNext()
Displays the next record of the result set. If the last record is being displayed, the first record will be displayed.

 o displayPrevious
 public void displayPrevious()
Displays the previous record of the result set. If the first record is being displayed, the last record will be displayed.

 o getConnection
 public SQLConnection getConnection()
Returns the SQL connection with which to access data.

Returns:
The SQL connection.
 o getCurrentRecord
 public synchronized int getCurrentRecord()
Returns the index of the record currently being displayed. Indices start at 0, and increment one for each of the records in the result set. Note that this is not the same as the record number.

Returns:
The index of the record currently being displayed. If there is no record being displayed, -1 is returned.
 o getLabelText
 public synchronized String getLabelText(int index)
Returns the text of the label at the given index.

Parameters:
index - The index of the label. Indices start at 0.
Returns:
The text of the label at the given index.
 o getQuery
 public String getQuery()
Returns the SQL query used to generate the form data.

Returns:
The SQL query.
 o getStringValueAt
 public synchronized String getStringValueAt(int index)
Returns the string value of the current record at the given index.

Parameters:
index - The index of the value. Indices start at 0.
Returns:
The value at the given index as a string.
 o getValueAt
 public synchronized Object getValueAt(int index)
Returns the value of the current record at the given index.

Parameters:
index - The index of the value. Indices start at 0.
Returns:
The value at the given index.
 o getWarnings
 public SQLWarning getWarnings()
Returns the warnings generated by the JDBC connection, statement, and result set. The warnings from the result set will be linked to the end of any statement warnings, which in turn are linked to the end of any connection warnings. Warnings are cleared when load() or clearWarnings() is called.

Returns:
The warnings generated by the connection, statement, and result set, or null if none.
 o load
 public void load()
Refreshes the view based on the state of the system. This runs the SQL query. The first record will be displayed. The labels are reconstructed, so any label text customization will be lost. The query and connection properties must be set before this method is called.

 o removeActionCompletedListener
 public void removeActionCompletedListener(ActionCompletedListener listener)
Removes a listener from being notified when a new record is displayed.

Parameters:
listener - The listener.
 o removeErrorListener
 public void removeErrorListener(ErrorListener listener)
Removes a listener from being notified when an error occurs.

Parameters:
listener - The listener.
 o setConnection
 public void setConnection(SQLConnection connection) throws PropertyVetoException
Sets the SQL connection with which to access data. This property is bound and constrained. Note that the data in the form will not change until a load() is done.

Parameters:
connection - The SQL connection.
Throws: PropertyVetoException
If the change is vetoed.
 o setLabelText
 public synchronized void setLabelText(int index,
                                       String text)
Sets the text of the label at the given index.

Parameters:
index - The index of the label. Indices start at 0.
text - The text of the label.
 o setQuery
 public void setQuery(String query) throws PropertyVetoException
Sets the SQL query used to generate the result set. This property is bound and constrained. Note that the data in the form will not change until a load() is done.

Parameters:
query - The SQL query.
Throws: PropertyVetoException
If the change is vetoed.

All Packages  Class Hierarchy  This Package  Previous  Next  Index