All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.ibm.as400.vaccess.SQLResultSetTableModel

java.lang.Object
   |
   +----com.sun.java.swing.table.AbstractTableModel
           |
           +----com.ibm.as400.vaccess.SQLResultSetTableModel

public class SQLResultSetTableModel
extends AbstractTableModel
implements Serializable
The SQLResultSetTableModel class represents a table that contains the result set generated by a SQL query using JDBC. This model can be used to create a table of the results.

This class should be used by users who wish to change the default interface for the table. When the default look and behavior is sufficient, SQLResultSetTablePane can be used.

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.

The data in the model is retrieved from the system when load() is called. If load() is not called, the model will contain no data. Not all data is retrieved at once, rather data is converted as needed (in chunks), to improve performance.

The data in this model is not editable. The individual cell values cannot be changed.

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.

SQLResultSetTableModel 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 SQLResultSetTableModel model = new SQLResultSetTableModel(connection, query);
// Set up window to hold table
JFrame frame = new JFrame ("My Window");
WindowListener l = new WindowAdapter()
{
// Close the model when window is closed.
public void windowClosing(WindowEvent e)
{
model.close();
connection.close();
}
};
frame.addWindowListener(l);
// Set up the error dialog adapter.
model.addErrorListener (new ErrorDialogAdapter (frame));
// Add the component and get data from system.
model.load();
JTable table = new JTable(model);
frame.getContentPane().add(new JScrollPane(table));
// Display the window
frame.setVisible(true)


Constructor Index

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

Method Index

 o addErrorListener(ErrorListener)
Adds a listener to be notified when an error occurs.
 o addPropertyChangeListener(PropertyChangeListener)
Adds a listener to be notified when the value of any bound property is changed.
 o addVetoableChangeListener(VetoableChangeListener)
Adds a listener to be notified when the value of any constrained property is changed.
 o addWorkingListener(WorkingListener)
Adds a listener to be notified when work starts and stops on potentially long-running operations.
 o clearWarnings()
Clears all SQL warnings.
 o close()
Closes the SQL result set this model represents.
 o getColumnClass(int)
Returns the class of the values in the column.
 o getColumnCount()
Returns the number of columns in the table.
 o getColumnID(int)
Returns the identifier of the column.
 o getColumnName(int)
Returns the name of the column for use in a table heading.
 o getColumnType(int)
Returns the SQL type of the data in a column.
 o getColumnWidth(int)
Returns the width of a column as a character count.
 o getConnection()
Returns the SQL connection with which to access data.
 o getQuery()
Returns the SQL query used to generate the table data.
 o getRowCount()
Returns the number of rows in the table.
 o getValueAt(int, int)
Returns the value at the specifed column and row.
 o getWarnings()
Returns the warnings generated by the JDBC connection, statement, and result set.
 o load()
Loads the table based on the state of the system.
 o removeErrorListener(ErrorListener)
Removes a listener from being notified when an error occurs.
 o removePropertyChangeListener(PropertyChangeListener)
Removes a listener from being notified when the value of any bound property is changed.
 o removeVetoableChangeListener(VetoableChangeListener)
Removes a listener from being notified when the value of any constrained property is changed.
 o removeWorkingListener(WorkingListener)
Removes a listener from being notified when work starts and stops on potentially long-running operations.
 o setConnection(SQLConnection)
Sets the SQL connection with which to access data.
 o setQuery(String)
Sets the SQL query used to generate the result set.

Constructors

 o SQLResultSetTableModel
 public SQLResultSetTableModel()
Constructs a SQLResultSetTableModel object.

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

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

Methods

 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 addPropertyChangeListener
 public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a listener to be notified when the value of any bound property is changed. The listener's propertyChange() method will be called.

Parameters:
listener - The listener.
 o addVetoableChangeListener
 public void addVetoableChangeListener(VetoableChangeListener listener)
Adds a listener to be notified when the value of any constrained property is changed. The listener's vetoableChange() method will be called.

Parameters:
listener - The listener.
 o addWorkingListener
 public void addWorkingListener(WorkingListener listener)
Adds a listener to be notified when work starts and stops on potentially long-running operations.

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

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

 o getColumnClass
 public synchronized Class getColumnClass(int columnIndex)
Returns the class of the values in the column. If an error occurs, null is returned.

Parameters:
columnIndex - The index of the column. Indices start at 0.
Returns:
The class of the column values.
Overrides:
getColumnClass in class AbstractTableModel
 o getColumnCount
 public synchronized int getColumnCount()
Returns the number of columns in the table.

Returns:
The number of columns in the table.
Overrides:
getColumnCount in class AbstractTableModel
 o getColumnID
 public synchronized String getColumnID(int columnIndex)
Returns the identifier of the column. This is the field name in the database. If an error occurs, null is returned.

Parameters:
columnIndex - The index of the column. Indices start at 0.
Returns:
The column identifier.
 o getColumnName
 public synchronized String getColumnName(int columnIndex)
Returns the name of the column for use in a table heading. If an error occurs, null is returned.

Parameters:
columnIndex - The index of the column. Indices start at 0.
Returns:
The column name.
Overrides:
getColumnName in class AbstractTableModel
 o getColumnType
 public synchronized int getColumnType(int columnIndex)
Returns the SQL type of the data in a column. If an error occurs, 0 is returned.

Parameters:
columnIndex - The index of the column. Indices start at 0.
Returns:
The SQL type of the column data.
 o getColumnWidth
 public synchronized int getColumnWidth(int columnIndex)
Returns the width of a column as a character count. If an error occurs, 0 is returned.

Parameters:
columnIndex - The index of the column. Indices start at 0.
Returns:
The width of the column expressed as a character count.
 o getConnection
 public SQLConnection getConnection()
Returns the SQL connection with which to access data.

Returns:
The SQL connection.
 o getQuery
 public String getQuery()
Returns the SQL query used to generate the table data.

Returns:
The SQL query.
 o getRowCount
 public int getRowCount()
Returns the number of rows in the table. Because of incremental data retrieval, this value may not be accurate.

Returns:
The number of rows in the table.
Overrides:
getRowCount in class AbstractTableModel
 o getValueAt
 public Object getValueAt(int rowIndex,
                          int columnIndex)
Returns the value at the specifed column and row. If an error occurs, null is returned.

Parameters:
rowIndex - The row index. Values start at 0.
columnIndex - The column index. Values start at 0.
Returns:
The value at the specified column and row.
Overrides:
getValueAt in class AbstractTableModel
 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()
Loads the table based on the state of the system. This causes the query to be run. The query and connection properties must be set before this method is called.

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

Parameters:
listener - The listener.
 o removePropertyChangeListener
 public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a listener from being notified when the value of any bound property is changed.

Parameters:
listener - The listener.
 o removeVetoableChangeListener
 public void removeVetoableChangeListener(VetoableChangeListener listener)
Removes a listener from being notified when the value of any constrained property is changed.

Parameters:
listener - The listener.
 o removeWorkingListener
 public void removeWorkingListener(WorkingListener listener)
Removes a listener from being notified when work starts and stops on potentially long-running operations.

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 will not change until a load() is done.

Parameters:
connection - The SQL connection.
Throws: PropertyVetoException
If the change is vetoed.
 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 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