Holger's
Java API

com.antelmann.sql
Class JDBCTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.antelmann.sql.JDBCTableModel
All Implemented Interfaces:
EditableComponent, Refreshable, Closeable, Serializable, TableModel
Direct Known Subclasses:
JDBCRowModel

public class JDBCTableModel
extends AbstractTableModel
implements EditableComponent, Closeable, Refreshable

JDBCTableModel provides a simple way to display/edit a table from a JDBC connection. An additional feature is that this model is also editable. Todo: eventually use CachedRowSets to be able to scroll through hudge data sets

Since:
10/24/2002
Author:
Holger Antelmann
See Also:
ResultSetTableModel, JDBCRowModel, JTable, ConnectionHelper, Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
JDBCTableModel(Connection con, String tableName)
           
JDBCTableModel(Connection con, String tableName, boolean updateable)
           
JDBCTableModel(Connection con, String tableName, int fetchSize)
           
JDBCTableModel(Connection con, String tableName, String[] columnNames)
           
JDBCTableModel(Connection con, String tableName, String[] columnNames, boolean updateable)
           
JDBCTableModel(Connection con, String tableName, String[] columnNames, boolean updateable, int fetchSize)
           
 
Method Summary
 void close()
          closes the embedded statement used
protected  void finalize()
           
 Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 String getColumnName(int column)
           
 String[] getColumns()
           
 Connection getConnection()
           
 Component getParentComponent()
           
 ResultSet getResultSet()
           
 int getRowCount()
           
 RowItem getRowItem(int row, int idColumn)
           
 RowItem getRowItem(int row, String idColumn)
           
 String getTableName()
           
 Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 boolean isEditable()
           
 boolean isInsertMode()
           
 boolean isRefreshOnSQLException()
           
 JDBCTableModel refresh()
           
 void refreshContent()
          refreshes the embedded content
 void setColumnNames(String[] columnNames)
          the values must correspond to actual column names of the underlying table; setting null means to simply use all existing column names (the default).
 void setEditable(boolean flag)
           
 void setInsertMode(boolean flag)
           
 void setParentComponent(Component parent)
           
 void setRefreshOnSQLException(boolean flag)
          if set to true, getValueAt(int, int) tries to recover by calling refresh().
 void setValueAt(Object value, int row, int column)
           
 
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
 

Constructor Detail

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName)
               throws SQLException
Throws:
SQLException

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName,
                      int fetchSize)
               throws SQLException
Throws:
SQLException

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName,
                      boolean updateable)
               throws SQLException
Throws:
SQLException

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName,
                      String[] columnNames)
               throws SQLException
Throws:
SQLException

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName,
                      String[] columnNames,
                      boolean updateable)
               throws SQLException
Throws:
SQLException

JDBCTableModel

public JDBCTableModel(Connection con,
                      String tableName,
                      String[] columnNames,
                      boolean updateable,
                      int fetchSize)
               throws SQLException
Throws:
SQLException
Method Detail

getConnection

public Connection getConnection()

getTableName

public String getTableName()

setColumnNames

public void setColumnNames(String[] columnNames)
the values must correspond to actual column names of the underlying table; setting null means to simply use all existing column names (the default). When the array is set to a non-null value, no error is thrown on this method call, but if the column names are incorrect, various exceptions may be thrown later on use of this model.


refreshContent

public void refreshContent()
                    throws IOException
Description copied from interface: Refreshable
refreshes the embedded content

Specified by:
refreshContent in interface Refreshable
Throws:
IOException - if the refresh failed

refresh

public JDBCTableModel refresh()
                       throws SQLException
Throws:
SQLException

isRefreshOnSQLException

public boolean isRefreshOnSQLException()
See Also:
setRefreshOnSQLException(boolean)

setRefreshOnSQLException

public void setRefreshOnSQLException(boolean flag)
if set to true, getValueAt(int, int) tries to recover by calling refresh(). This allows to use the result set over transaction boundaries.


getResultSet

public ResultSet getResultSet()

isEditable

public boolean isEditable()
Specified by:
isEditable in interface EditableComponent

setEditable

public void setEditable(boolean flag)
Specified by:
setEditable in interface EditableComponent

isInsertMode

public boolean isInsertMode()

setInsertMode

public void setInsertMode(boolean flag)

setParentComponent

public void setParentComponent(Component parent)

getParentComponent

public Component getParentComponent()

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface TableModel

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface TableModel

getValueAt

public Object getValueAt(int row,
                         int column)
Specified by:
getValueAt in interface TableModel

getRowItem

public RowItem getRowItem(int row,
                          int idColumn)
                   throws SQLException
Throws:
SQLException

getRowItem

public RowItem getRowItem(int row,
                          String idColumn)
                   throws SQLException
Throws:
SQLException

getColumnName

public String getColumnName(int column)
Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel

getColumns

public String[] getColumns()
                    throws SQLException
Throws:
SQLException

getColumnClass

public Class<?> getColumnClass(int column)
Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel

setValueAt

public void setValueAt(Object value,
                       int row,
                       int column)
Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel

finalize

protected void finalize()
                 throws IOException
Overrides:
finalize in class Object
Throws:
IOException

close

public void close()
           throws IOException
closes the embedded statement used

Specified by:
close in interface Closeable
Throws:
IOException


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads