HOME

com.ultraswing
Class ResultSetTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--javax.swing.table.DefaultTableModel
              |
              +--com.ultraswing.DefaultSortableTableModel
                    |
                    +--com.ultraswing.ResultSetTableModel
All Implemented Interfaces:
Serializable, SortableTableModel, TableModel

public class ResultSetTableModel
extends DefaultSortableTableModel

A TableModel object which takes values from a JDBC ResultSet object.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.DefaultTableModel
columnIdentifiers, dataVector
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
ResultSetTableModel(ResultSet resultset)
          Constructs a TableModel from a ResultSet.
ResultSetTableModel(String driverClassName, String url, String query)
          Constructs a ResultSetMetaData.
ResultSetTableModel(String driverClassName, String url, String username, String password, String query)
          Constructs a ResultSetMetaData.
 
Method Summary
 void close()
          Closes the database resources
protected  void finalize()
           
 Class getColumnClass(int column)
          Returns the column Class
 int getColumnCount()
          Returns number of columns
 String getColumnName(int column)
          Returns the column name
 int getRowCount()
          Returns the number of rows
 Object getValueAt(int row, int column)
          This is the key method of TableModel: it returns the value at each cell of the table.
 void setColumnName(int column, String columnName)
          This method should be called before this object is passed to table object.
 void setColumnNameMap(Map map)
          This method should be called before this object is passed table object.
 void setSortByColumn(int column, boolean ascending)
          Sets the sorting order of colum
 void setValueAt(Object value, int row, int column)
          Sets the object value for the cell at column and row.
 
Methods inherited from class com.ultraswing.DefaultSortableTableModel
getSortedColumnIndex, isAscending, isSortable
 
Methods inherited from class javax.swing.table.DefaultTableModel
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getDataVector, insertRow, insertRow, isCellEditable, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener
 

Constructor Detail

ResultSetTableModel

public ResultSetTableModel(String driverClassName,
                           String url,
                           String query)
                    throws ClassNotFoundException,
                           SQLException
Constructs a ResultSetMetaData. Attempts to establish a connection to the given database URL, and executes the passed query

Parameters:
driverClassName - JDBC driver class name
url - a database url of the form jdbc:subprotocol:subname
query - an SQL statement to be sent to the database, typically a static SQL SELECT statement
Throws:
ClassNotFoundException - raised if JDBC driver classes are not found in class path
SQLException - raised if SQL query can't be successfully excecuted

ResultSetTableModel

public ResultSetTableModel(String driverClassName,
                           String url,
                           String username,
                           String password,
                           String query)
                    throws ClassNotFoundException,
                           SQLException
Constructs a ResultSetMetaData. Attempts to establish a connection to the given database URL, and executes the passed query

Parameters:
driverClassName - JDBC driver class name
url - a database url of the form jdbc:subprotocol:subname
username - the database user on whose behalf the connection is being made
password - the user's password
query - an SQL statement to be sent to the database, typically a static SQL SELECT statement
Throws:
ClassNotFoundException - raised if JDBC driver classes are not found in class path
SQLException - raised if SQL query can't be successfully excecuted

ResultSetTableModel

public ResultSetTableModel(ResultSet resultset)
                    throws SQLException
Constructs a TableModel from a ResultSet.

Method Detail

close

public void close()
Closes the database resources


finalize

protected void finalize()
Overrides:
finalize in class Object

getColumnCount

public int getColumnCount()
Returns number of columns

Specified by:
getColumnCount in interface TableModel
Overrides:
getColumnCount in class DefaultTableModel

getRowCount

public int getRowCount()
Returns the number of rows

Specified by:
getRowCount in interface TableModel
Overrides:
getRowCount in class DefaultTableModel

getColumnName

public String getColumnName(int column)
Returns the column name

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class DefaultTableModel
Parameters:
column - column index

setColumnName

public void setColumnName(int column,
                          String columnName)
This method should be called before this object is passed to table object. This method takes precedence over setColumnNameMap


setColumnNameMap

public void setColumnNameMap(Map map)
This method should be called before this object is passed table object.


getColumnClass

public Class getColumnClass(int column)
Returns the column Class

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
column - column index

getValueAt

public Object getValueAt(int row,
                         int column)
This is the key method of TableModel: it returns the value at each cell of the table. We use strings in this case. If anything goes wrong, we return the exception as a string, so it will be displayed in the table. Note that SQL row and column numbers start at 1, but TableModel column numbers start at 0.

Specified by:
getValueAt in interface TableModel
Overrides:
getValueAt in class DefaultTableModel

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Sets the object value for the cell at column and row. This method will generate a tableChanged notification.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class DefaultTableModel
Parameters:
value - the new value; this can be null
row - the row whose value is to be changed
column - the column whose value is to be changed

setSortByColumn

public void setSortByColumn(int column,
                            boolean ascending)
Sets the sorting order of colum

Specified by:
setSortByColumn in interface SortableTableModel
Overrides:
setSortByColumn in class DefaultSortableTableModel
Parameters:
column - colum index
ascending - if true, sort the specified column into ascending order

HOME

Copyright © 2002 iReasoning Networks. All Rights Reserved.