All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.vaccess.SQLResultSetFormPane
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----com.sun.java.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:
- ActionCompletedEvent
- ErrorEvent
- PropertyChangeEvent
// 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)
-
SQLResultSetFormPane()
- Constructs a SQLResultSetFormPane object.
-
SQLResultSetFormPane(SQLConnection, String)
- Constructs a SQLResultSetFormPane object.
-
addActionCompletedListener(ActionCompletedListener)
- Adds a listener to be notified when a new record is displayed.
-
addErrorListener(ErrorListener)
- Adds a listener to be notified when an error occurs.
-
clearWarnings()
- Clears all SQL warnings.
-
close()
- Closes the SQL result set this form represents.
-
displayFirst()
- Displays the first record of the result set.
-
displayLast()
- Displays the last record of the result set.
-
displayNext()
- Displays the next record of the result set.
-
displayPrevious()
- Displays the previous record of the result set.
-
getConnection()
- Returns the SQL connection with which to access data.
-
getCurrentRecord()
- Returns the index of the record currently being displayed.
-
getLabelText(int)
- Returns the text of the label at the given index.
-
getQuery()
- Returns the SQL query used to generate the form data.
-
getStringValueAt(int)
- Returns the string value of the current record at the given index.
-
getValueAt(int)
- Returns the value of the current record at the given index.
-
getWarnings()
- Returns the warnings generated by the JDBC connection, statement, and
result set.
-
load()
- Refreshes the view based on the state of the system.
-
removeActionCompletedListener(ActionCompletedListener)
- Removes a listener from being notified when a new record is displayed.
-
removeErrorListener(ErrorListener)
- Removes a listener from being notified when an error occurs.
-
setConnection(SQLConnection)
- Sets the SQL connection with which to access data.
-
setLabelText(int, String)
- Sets the text of the label at the given index.
-
setQuery(String)
- Sets the SQL query used to generate the result set.
SQLResultSetFormPane
public SQLResultSetFormPane()
- Constructs a SQLResultSetFormPane object.
SQLResultSetFormPane
public SQLResultSetFormPane(SQLConnection connection,
String query)
- Constructs a SQLResultSetFormPane object.
- Parameters:
- connection - The SQL connection.
- query - The SQL query.
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.
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.
clearWarnings
public void clearWarnings()
- Clears all SQL warnings.
close
public void close()
- Closes the SQL result set this form represents.
displayFirst
public void displayFirst()
- Displays the first record of the result set.
displayLast
public void displayLast()
- Displays the last record of the result set.
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.
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.
getConnection
public SQLConnection getConnection()
- Returns the SQL connection with which to access data.
- Returns:
- The SQL connection.
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.
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.
getQuery
public String getQuery()
- Returns the SQL query used to generate the form data.
- Returns:
- The SQL query.
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.
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.
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.
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.
removeActionCompletedListener
public void removeActionCompletedListener(ActionCompletedListener listener)
- Removes a listener from being notified when a new record is displayed.
- Parameters:
- listener - The listener.
removeErrorListener
public void removeErrorListener(ErrorListener listener)
- Removes a listener from being notified when an error occurs.
- Parameters:
- listener - The listener.
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.
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.
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