SQLResultSetTablePane is implemented using the model-view-controller paradigm, in which the data and the user interface are separated into different classes. The implementation integrates SQLResultSetTableModel with the Java™ Foundation Classes' (JFC) JTable. The SQLResultSetTableModel class manages the results of the query and JTable displays the results graphically and handles user interaction.
SQLResultSetTablePane provides enough functionality for most requirements. However, if a caller needs more control of the JFC component, then the caller can use SQLResultSetTableModel directly and provide customized integration with a different graphical user interface component.
To use an SQLResultSetTableModel, set the connection and query properties. Set these properties by using the constructor or the setConnection() and setQuery() methods. Use load() to execute the query and load the results. When the results are no longer needed, call close() to ensure that the result set is closed.
The following example creates an SQLResultSetTableModel object and presents it with a JTable:
// Create an SQLResultSetTableModel // object. Assume that "connection" // is an SQLConnection object that is // created and initialized elsewhere. SQLResultSetTableModel tableModel = new SQLResultSetTableModel (connection, "SELECT * FROM QIWS.QCUSTCDT"); // Load the results. tableModel.load (); // Create a JTable for the model. JTable table = new JTable (tableModel); // Add the table to a frame. Assume // that "frame" is a JFrame created // elsewhere. frame.getContentPane ().add (table);