All Packages Class Hierarchy This Package Previous Next Index
Class com.ibm.as400.vaccess.SQLResultSetTablePane
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----javax.swing.JComponent
|
+----com.ibm.as400.vaccess.SQLResultSetTablePane
- public class SQLResultSetTablePane
- extends JComponent
- implements Serializable
The SQLResultSetTablePane class represents a table that contains the result
set generated by a SQL query using JDBC.
The data in the table is retrieved from the system when
load() is called. If load() is not called,
the table 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.
The data in this table is not editable, the individual
cell values cannot be changed.
SQLResultSetTablePane objects generate the following events:
- ErrorEvent
- ListSelectionEvent
- 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 SQLResultSetTablePane pane = new SQLResultSetTablePane(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)
-
SQLResultSetTablePane()
- Constructs a SQLResultSetTablePane object.
-
SQLResultSetTablePane(SQLConnection, String)
- Constructs a SQLResultSetTablePane object.
-
addErrorListener(ErrorListener)
- Adds a listener to be notified when an error occurs.
-
addListSelectionListener(ListSelectionListener)
- Adds a listener to be notified when the selection changes.
-
addPropertyChangeListener(PropertyChangeListener)
- Adds a listener to be notified when the value of any bound
property is changed.
-
addVetoableChangeListener(VetoableChangeListener)
- Adds a listener to be notified when the value of any constrained
property is changed.
-
clearWarnings()
- Clears all SQL warnings.
-
close()
- Closes the SQL result set this table represents.
-
getColumnModel()
- Returns the column model for this table.
-
getColumnTitle(int)
- Returns the title of a column.
-
getColumnWidth(int)
- Returns the width of a column.
-
getConnection()
- Returns the SQL connection with which to access data.
-
getDataModel()
- Returns the data model for the table.
-
getGridColor()
- Returns the color used to draw grid lines.
-
getQuery()
- Returns the SQL query used to generate the table data.
-
getSelectionModel()
- Returns the ListSelectionModel that is used to maintain row selection state.
-
getShowHorizontalLines()
- Returns whether horizontal lines are drawn between rows.
-
getShowVerticalLines()
- Returns whether vertical lines are drawn between columns.
-
getStringValueAt(int, int)
- Returns the string value at the specifed row and column.
-
getValueAt(int, int)
- Returns the value at the specifed row and column.
-
getWarnings()
- Returns the warnings generated by the JDBC connection, statement, and
result set.
-
load()
- Loads the table based on the state of the system.
-
refreshHeadings()
- Updates the table header to match the result set data.
-
removeErrorListener(ErrorListener)
- Removes a listener from being notified when an error occurs.
-
removeListSelectionListener(ListSelectionListener)
- Removes a listener from being notified when the selection changes.
-
removePropertyChangeListener(PropertyChangeListener)
- Removes a listener from being notified when the value of any bound
property is changed.
-
removeVetoableChangeListener(VetoableChangeListener)
- Removes a listener from being notified when the value of any constrained
property is changed.
-
setColumnTitle(int, String)
- Sets the title of a column.
-
setColumnWidth(int, int)
- Sets the width of a column.
-
setConnection(SQLConnection)
- Sets the SQL connection with which to access data.
-
setGridColor(Color)
- Sets the color used to draw grid lines.
-
setQuery(String)
- Sets the SQL query used to build the table.
-
setSelectionModel(ListSelectionModel)
- Sets the ListSelectionModel that is used to maintain row selection state.
-
setShowHorizontalLines(boolean)
- Sets whether horizontal lines are drawn between rows.
-
setShowVerticalLines(boolean)
- Sets whether vertical lines are drawn between columns.
SQLResultSetTablePane
public SQLResultSetTablePane()
- Constructs a SQLResultSetTablePane object.
SQLResultSetTablePane
public SQLResultSetTablePane(SQLConnection connection,
String query)
- Constructs a SQLResultSetTablePane object.
- Parameters:
- connection - The SQL connection.
- query - The SQL query.
addErrorListener
public void addErrorListener(ErrorListener listener)
- Adds a listener to be notified when an error occurs.
- Parameters:
- listener - The listener.
addListSelectionListener
public void addListSelectionListener(ListSelectionListener listener)
- Adds a listener to be notified when the selection changes.
- Parameters:
- listener - The listener.
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
- Adds a listener to be notified when the value of any bound
property is changed.
- Parameters:
- listener - The listener.
- Overrides:
- addPropertyChangeListener in class JComponent
addVetoableChangeListener
public void addVetoableChangeListener(VetoableChangeListener listener)
- Adds a listener to be notified when the value of any constrained
property is changed.
- Parameters:
- listener - The listener.
- Overrides:
- addVetoableChangeListener in class JComponent
clearWarnings
public void clearWarnings()
- Clears all SQL warnings.
close
public void close()
- Closes the SQL result set this table represents.
getColumnModel
public TableColumnModel getColumnModel()
- Returns the column model for this table.
- Returns:
- Model for this table's columns.
getColumnTitle
public String getColumnTitle(int columnIndex)
- Returns the title of a column. This is used for the table column heading.
If an error occurs, null is returned.
- Parameters:
- columnIndex - The index of the column. Indices start at 0.
- Returns:
- The title of the column.
getColumnWidth
public int getColumnWidth(int columnIndex)
- Returns the width of a column.
If an error occurs, 0 is returned.
- Parameters:
- columnIndex - The index of the column. Indices start at 0.
- Returns:
- The width of the column.
getConnection
public SQLConnection getConnection()
- Returns the SQL connection with which to access data.
- Returns:
- The SQL connection.
getDataModel
public SQLResultSetTableModel getDataModel()
- Returns the data model for the table.
- Returns:
- The data model for the table.
getGridColor
public Color getGridColor()
- Returns the color used to draw grid lines.
- Returns:
- The color used to draw grid lines.
getQuery
public String getQuery()
- Returns the SQL query used to generate the table data.
- Returns:
- The SQL query.
getSelectionModel
public ListSelectionModel getSelectionModel()
- Returns the ListSelectionModel that is used to maintain row selection state.
- Returns:
- The model that provides row selection state.
getShowHorizontalLines
public boolean getShowHorizontalLines()
- Returns whether horizontal lines are drawn between rows.
- Returns:
- true if horizontal lines are to be drawn; false otherwise.
getShowVerticalLines
public boolean getShowVerticalLines()
- Returns whether vertical lines are drawn between columns.
- Returns:
- true if vertical lines are to be drawn; false otherwise.
getStringValueAt
public String getStringValueAt(int rowIndex,
int columnIndex)
- Returns the string value at the specifed row and column.
Indices start at 0.
If an error occurs, null is returned.
- Parameters:
- rowIndex - The row index.
- columnIndex - The column index.
- Returns:
- The value at the specified row and column as a string.
getValueAt
public Object getValueAt(int rowIndex,
int columnIndex)
- Returns the value at the specifed row and column.
Indices start at 0.
If an error occurs, null is returned.
- Parameters:
- rowIndex - The row index.
- columnIndex - The column index.
- Returns:
- The value at the specified row and column.
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()
- 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.
The table heading is reconstructed to ensure it matches
the data, so any column customization will be lost.
refreshHeadings
public void refreshHeadings()
- Updates the table header to match the result set data.
Any column customization will be lost.
removeErrorListener
public void removeErrorListener(ErrorListener listener)
- Removes a listener from being notified when an error occurs.
- Parameters:
- listener - The listener.
removeListSelectionListener
public void removeListSelectionListener(ListSelectionListener listener)
- Removes a listener from being notified when the selection changes.
- Parameters:
- listener - The listener.
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.
- Overrides:
- removePropertyChangeListener in class JComponent
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.
- Overrides:
- removeVetoableChangeListener in class JComponent
setColumnTitle
public void setColumnTitle(int columnIndex,
String title)
- Sets the title of a column. This is used for the table column heading.
- Parameters:
- columnIndex - The index of column. Indices start at 0.
- title - The title for the column.
setColumnWidth
public void setColumnWidth(int columnIndex,
int width)
- Sets the width of a column.
- Parameters:
- columnIndex - The index of column. Indices start at 0.
- width - The column width.
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 table will not change until a
load() is done.
- Parameters:
- connection - The SQL connection.
- Throws: PropertyVetoException
- If the change is vetoed.
setGridColor
public void setGridColor(Color color)
- Sets the color used to draw grid lines.
- Parameters:
- color - The color used to draw the grid lines.
setQuery
public void setQuery(String query) throws PropertyVetoException
- Sets the SQL query used to build the table.
This property is bound and constrained.
Note that the data in the table will not change until a
load() is done.
- Parameters:
- query - The SQL query.
- Throws: PropertyVetoException
- If the change is vetoed.
setSelectionModel
public void setSelectionModel(ListSelectionModel model)
- Sets the ListSelectionModel that is used to maintain row selection state.
- Parameters:
- model - The model that provides the row selection state.
setShowHorizontalLines
public void setShowHorizontalLines(boolean show)
- Sets whether horizontal lines are drawn between rows.
- Parameters:
- show - true if horizontal lines are to be drawn; false otherwise.
setShowVerticalLines
public void setShowVerticalLines(boolean show)
- Sets whether vertical lines are drawn between columns.
- Parameters:
- show - true if vertical lines are to be drawn; false otherwise.
All Packages Class Hierarchy This Package Previous Next Index