Class SQLResultSetTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- com.ibm.as400.vaccess.SQLResultSetTableModel
-
- All Implemented Interfaces:
- java.io.Serializable, javax.swing.table.TableModel
Deprecated.Use Java Swing instead, along with the classes in package com.ibm.as400.access
public class SQLResultSetTableModel extends javax.swing.table.AbstractTableModel implements java.io.Serializable
The SQLResultSetTableModel class represents the data in a JDBC result set generated by an SQL query. This class implements the underlying model for a table in a graphical user interface. Use this class if you want to customize the graphical user interface that presents a table. If you do not need to customize the graphical user interface, then use SQLResultSetTablePane instead.You must specify an SQLConnection object and SQL query string to use for generating the data. Alternately, you can specify a ResultSet object directly. If you specify a ResultSet object, it will override any SQLConnection or SQL query previously set. In addition, if you specify a ResultSet, this class will use memory more efficiently if you create the ResultSet as scrollable.
You must explicitly call load() to load the information from the result set. The model will be empty until load() is called. If the query or result set includes updatable columns, then the respective columns will be editable.
This class assumes that the necessary JDBC driver(s) are already registered.
Call close() to ensure that the result set is closed when this table is no longer needed.
Most errors are reported as ErrorEvents rather than throwing exceptions. Listen for ErrorEvents in order to diagnose and recover from error conditions.
SQLResultSetTableModel objects generate the following events:
- ErrorEvent
- PropertyChangeEvent
- TableModelEvent
- WorkingEvent
This example creates an SQLResultSetTableModel using an SQLConnection and query and displays it using a JTable:
// Register the IBM Toolbox for Java JDBC driver. DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
// Create the SQLResultSetTableModel object. SQLConnection connection = new SQLConnection("jdbc:as400://MySystem", "Userid", "Password"); String query = "SELECT * FROM MYLIB.MYTABLE"; SQLResultSetTableModel model = new SQLResultSetTableModel(connection, query);
// Create the enclosing JTable and put it in a JFrame. JTable table = new JTable(model); JFrame frame = new JFrame("My Window"); frame.getContentPane().add(new JScrollPane(table));
// Set up the error dialog adapter. model.addErrorListener(new ErrorDialogAdapter(frame));
// Display the JFrame. frame.pack(); frame.show();
// Load the contents of the model. model.load();This example creates an SQLResultSetTableModel using a ResultSet and displays it using a JTable:
// Register the IBM Toolbox for Java JDBC driver. DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
// Use JDBC to execute the SQL query directly. Connection connection = DriverManager.getConnection("MySystem", "Userid", "Password"); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = statement.executeQuery("SELECT * FROM MYLIB.MYTABLE");
// Create the SQLResultSetTableModel object. SQLResultSetTableModel model = new SQLResultSetTableModel(rs);
// Create the enclosing JTable and put it in a JFrame. JTable table = new JTable(model); JFrame frame = new JFrame("My Window"); frame.getContentPane().add(new JScrollPane(table));
// Set up the error dialog adapter. model.addErrorListener(new ErrorDialogAdapter(frame));
// Display the JFrame. frame.pack(); frame.show();
// Load the contents of the model. model.load();- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SQLResultSetTableModel()
Deprecated.Constructs a SQLResultSetTableModel object.SQLResultSetTableModel(java.sql.ResultSet resultSet, boolean cacheAll)
Deprecated.Constructs a SQLResultSetTableModel object.SQLResultSetTableModel(SQLConnection connection, java.lang.String query)
Deprecated.Constructs a SQLResultSetTableModel object.
-
Method Summary
Methods Modifier and Type Method and Description void
addErrorListener(ErrorListener listener)
Deprecated.Adds a listener to be notified when an error occurs.void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.Adds a listener to be notified when the value of any bound property changes.void
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.Adds a listener to be notified when the value of any constrained property changes.void
addWorkingListener(WorkingListener listener)
Deprecated.Adds a listener to be notified when work starts and stops on potentially long-running operations.void
clearWarnings()
Deprecated.Clears all SQL warnings.void
close()
Deprecated.Closes the result set.java.lang.Class
getColumnClass(int columnIndex)
Deprecated.Returns the class of the values in the column.int
getColumnCount()
Deprecated.Returns the number of columns in the table.java.lang.String
getColumnID(int columnIndex)
Deprecated.Returns the column identifier.java.lang.String
getColumnName(int columnIndex)
Deprecated.Returns the column name.int
getColumnType(int columnIndex)
Deprecated.Returns the column type.int
getColumnWidth(int columnIndex)
Deprecated.Returns the column width.SQLConnection
getConnection()
Deprecated.Returns the SQL connection.java.lang.String
getQuery()
Deprecated.Returns the SQL query.java.sql.ResultSet
getResultSet()
Deprecated.Returns the SQL result set.int
getRowCount()
Deprecated.Returns the number of rows in the table.java.lang.Object
getValueAt(int rowIndex, int columnIndex)
Deprecated.Returns the value at the specifed row and column.java.sql.SQLWarning
getWarnings()
Deprecated.Returns the SQL warnings.boolean
isCellEditable(int rowIndex, int columnIndex)
Deprecated.Indicates if the cell is editable.void
load()
Deprecated.Loads the data in the table.void
removeErrorListener(ErrorListener listener)
Deprecated.Removes an error listener.void
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.Removes a property change listener.void
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.Removes a vetoable change listener.void
removeWorkingListener(WorkingListener listener)
Deprecated.Removes a working listener.void
setConnection(SQLConnection connection)
Deprecated.Sets the SQL connection.void
setQuery(java.lang.String query)
Deprecated.Sets the SQL query.void
setResultSet(java.sql.ResultSet resultSet)
Deprecated.Sets the SQL result set used to build the table.void
setTable(javax.swing.JTable table)
Deprecated.Set a reference to the JTable so that the selected row can be updated after fireTableRowsInserted.void
setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
Deprecated.Sets the value at the specifed row and column.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Constructor Detail
-
SQLResultSetTableModel
public SQLResultSetTableModel()
Deprecated.Constructs a SQLResultSetTableModel object.
-
SQLResultSetTableModel
public SQLResultSetTableModel(SQLConnection connection, java.lang.String query)
Deprecated.Constructs a SQLResultSetTableModel object.- Parameters:
connection
- The SQL connection.query
- The SQL query.
-
SQLResultSetTableModel
public SQLResultSetTableModel(java.sql.ResultSet resultSet, boolean cacheAll)
Deprecated.Constructs a SQLResultSetTableModel object.- Parameters:
resultSet
- The SQL result set.cacheAll
- true to cache the entire result set when load() is called, false to cache parts of the result set as they are needed. Passing true may result in slow initial presentation of the data. However, it may be necessary to pass true if the result set is expected to close when the model is still needed.
-
-
Method Detail
-
addErrorListener
public void addErrorListener(ErrorListener listener)
Deprecated.Adds a listener to be notified when an error occurs.- Parameters:
listener
- The listener.
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.Adds a listener to be notified when the value of any bound property changes.- Parameters:
listener
- The listener.
-
addVetoableChangeListener
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.Adds a listener to be notified when the value of any constrained property changes.- Parameters:
listener
- The listener.
-
addWorkingListener
public void addWorkingListener(WorkingListener listener)
Deprecated.Adds a listener to be notified when work starts and stops on potentially long-running operations.- Parameters:
listener
- The listener.
-
clearWarnings
public void clearWarnings()
Deprecated.Clears all SQL warnings.
-
close
public void close()
Deprecated.Closes the result set.
-
getColumnClass
public java.lang.Class getColumnClass(int columnIndex)
Deprecated.Returns the class of the values in the column.- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
- Parameters:
columnIndex
- The column index (0-based).- Returns:
- The class of the column values, or null if an error occurs.
-
getColumnCount
public int getColumnCount()
Deprecated.Returns the number of columns in the table.- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
- Returns:
- The number of columns in the table, or 0 if an error occurs.
-
getColumnID
public java.lang.String getColumnID(int columnIndex)
Deprecated.Returns the column identifier. This corresponds to the field name in the database.- Parameters:
columnIndex
- The column index (0-based).- Returns:
- The column identifier, or null if an error occurs.
-
getColumnName
public java.lang.String getColumnName(int columnIndex)
Deprecated.Returns the column name. This corresponds to the column label in the database.- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
- Parameters:
columnIndex
- The column index (0-based).- Returns:
- The column name, or null if an error occurs.
-
getColumnType
public int getColumnType(int columnIndex)
Deprecated.Returns the column type.- Parameters:
columnIndex
- The column index (0-based).- Returns:
- The column type, or 0 if an error occurs.
-
getColumnWidth
public int getColumnWidth(int columnIndex)
Deprecated.Returns the column width.- Parameters:
columnIndex
- The column index (0-based).- Returns:
- The column width, in characters, or 0 if an error occurs.
-
getConnection
public SQLConnection getConnection()
Deprecated.Returns the SQL connection.- Returns:
- The SQL connection.
-
getQuery
public java.lang.String getQuery()
Deprecated.Returns the SQL query.- Returns:
- The SQL query.
-
getResultSet
public java.sql.ResultSet getResultSet()
Deprecated.Returns the SQL result set.- Returns:
- The SQL result set.
-
getRowCount
public int getRowCount()
Deprecated.Returns the number of rows in the table. Because of incremental data retrieval, this value may not be accurate.- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
- Returns:
- The number of rows in the table.
-
getValueAt
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
Deprecated.Returns the value at the specifed row and column.- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
- Parameters:
rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).- Returns:
- The value at the specified row and column.
-
getWarnings
public java.sql.SQLWarning getWarnings()
Deprecated.Returns the SQL warnings.- Returns:
- The SQL warnings.
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
Deprecated.Indicates if the cell is editable.- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
- Parameters:
rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).- Returns:
- true if the cell is editable, false otherwise or if an error occurs.
-
load
public void load()
Deprecated.Loads the data in the table.
-
removeErrorListener
public void removeErrorListener(ErrorListener listener)
Deprecated.Removes an error listener.- Parameters:
listener
- The listener.
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Deprecated.Removes a property change listener.- Parameters:
listener
- The listener.
-
removeVetoableChangeListener
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Deprecated.Removes a vetoable change listener.- Parameters:
listener
- The listener.
-
removeWorkingListener
public void removeWorkingListener(WorkingListener listener)
Deprecated.Removes a working listener.- Parameters:
listener
- The listener.
-
setConnection
public void setConnection(SQLConnection connection) throws java.beans.PropertyVetoException
Deprecated.Sets the SQL connection. The data will not change until load() is called.- Parameters:
connection
- The SQL connection.- Throws:
java.beans.PropertyVetoException
- If the change is vetoed.
-
setQuery
public void setQuery(java.lang.String query) throws java.beans.PropertyVetoException
Deprecated.Sets the SQL query. The data will not change until load() is called.- Parameters:
query
- The SQL query.- Throws:
java.beans.PropertyVetoException
- If the change is vetoed.
-
setResultSet
public void setResultSet(java.sql.ResultSet resultSet)
Deprecated.Sets the SQL result set used to build the table. If this is set, it is used instead of the SQL connection and SQL query. The data will not change until load() is called.- Parameters:
resultSet
- The SQL result set.
-
setValueAt
public void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
Deprecated.Sets the value at the specifed row and column.- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
- Parameters:
value
- The value.rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).
-
setTable
public void setTable(javax.swing.JTable table)
Deprecated.Set a reference to the JTable so that the selected row can be updated after fireTableRowsInserted.- Parameters:
table
-
-
-