public class SQLResultSetTableModel
extends javax.swing.table.AbstractTableModel
implements java.io.Serializable
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:
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();
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.
|
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.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
public SQLResultSetTableModel()
public SQLResultSetTableModel(SQLConnection connection, java.lang.String query)
connection
- The SQL connection.query
- The SQL query.public SQLResultSetTableModel(java.sql.ResultSet resultSet, boolean cacheAll)
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.public void addErrorListener(ErrorListener listener)
listener
- The listener.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.public void addWorkingListener(WorkingListener listener)
listener
- The listener.public void clearWarnings()
public void close()
public java.lang.Class getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
columnIndex
- The column index (0-based).public int getColumnCount()
getColumnCount
in interface javax.swing.table.TableModel
public java.lang.String getColumnID(int columnIndex)
columnIndex
- The column index (0-based).public java.lang.String getColumnName(int columnIndex)
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.AbstractTableModel
columnIndex
- The column index (0-based).public int getColumnType(int columnIndex)
columnIndex
- The column index (0-based).public int getColumnWidth(int columnIndex)
columnIndex
- The column index (0-based).public SQLConnection getConnection()
public java.lang.String getQuery()
public java.sql.ResultSet getResultSet()
public int getRowCount()
getRowCount
in interface javax.swing.table.TableModel
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface javax.swing.table.TableModel
rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).public java.sql.SQLWarning getWarnings()
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).public void load()
public void removeErrorListener(ErrorListener listener)
listener
- The listener.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener.public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener.public void removeWorkingListener(WorkingListener listener)
listener
- The listener.public void setConnection(SQLConnection connection) throws java.beans.PropertyVetoException
connection
- The SQL connection.java.beans.PropertyVetoException
- If the change is vetoed.public void setQuery(java.lang.String query) throws java.beans.PropertyVetoException
query
- The SQL query.java.beans.PropertyVetoException
- If the change is vetoed.public void setResultSet(java.sql.ResultSet resultSet)
resultSet
- The SQL result set.public void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
value
- The value.rowIndex
- The row index (0-based).columnIndex
- The column index (0-based).public void setTable(javax.swing.JTable table)
table
-