public class IlvJDBCTableModel extends AbstractTableModel
IlvJDBCTableMode
is an implementation of the Swing
TableModel
that connects to a database through JDBC 2.0. This
implementation is a read-only version of a TableModel
.
Note: since JViews 6.5
IlvRowSetTableModel
is a read and write
implementation that instead of using JDBC 2.0 API relies on
RowSet
API. This is the recommended class to use if you don't
need threaded loading of the data or if you need write capabilities.IlvRowSetTableModel
,
Serialized FormlistenerList
Constructor and Description |
---|
IlvJDBCTableModel()
Creates an
IlvJDBCTableModel . |
IlvJDBCTableModel(Connection connection,
String query)
Creates and initializes an
IlvJDBCTableModel from a
java.sql.Connection and an SQL query. |
IlvJDBCTableModel(Connection connection,
String query,
Object[] queryParameters)
Creates and initializes an
IlvJDBCTableModel from a
java.sql.Connection and an SQL query. |
IlvJDBCTableModel(ResultSet resultSet)
Creates and initializes an
IlvJDBCTableModel from a
java.sql.ResultSet . |
IlvJDBCTableModel(String databaseURL,
String user,
String passwd,
String driverName,
String query)
Creates and initializes an
IlvJDBCTableModel from a set of
JDBC parameters. |
IlvJDBCTableModel(String databaseURL,
String user,
String passwd,
String driverName,
String query,
Object[] queryParameters)
Creates and initializes an
IlvJDBCTableModel from a set of
JDBC parameters. |
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
Ensures that all the
IlvJDBCTableModel resources are released. |
Class<?> |
getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.
|
int |
getColumnCount()
Returns the number of columns in this table model.
|
String |
getColumnName(int columnIndex)
Returns the name of the column at index
columnIndex . |
int |
getMaximumCacheSize()
Returns the maximum size of the internal cache of the
IlvJDBCTableModel . |
ResultSet |
getResultSet()
Returns the
ResultSet used internally by this
IlvJDBCTableModel to query the database. |
int |
getRowCount()
Returns the number of row in this table model.
|
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value at the specified indexes.
|
boolean |
isThreadingEnabled()
Sets whether or not threading must be used to compute the internal cache.
|
void |
join()
This method must be called to wait for the execution of the
IlvJDBCTableModel caching thread to be finished. |
protected void |
releaseResources()
Releases the resources acquired by the
IlvJDBCTableModel . |
void |
setConnection(Connection connection,
String query)
Initializes an
IlvJDBCTableModel with a
java.sql.Connection and an SQL query. |
void |
setConnection(Connection connection,
String query,
Object[] queryParameters)
Initializes an
IlvJDBCTableModel with a
java.sql.Connection and an SQL query. |
void |
setConnectionParameters(String databaseURL,
String user,
String passwd,
String driverName,
String query)
Initializes an
IlvJDBCTableModel with a set of JDBC
parameters. |
void |
setConnectionParameters(String databaseURL,
String user,
String passwd,
String driverName,
String query,
Object[] queryParameters)
Initializes an
IlvJDBCTableModel with a set of JDBC
parameters. |
void |
setMaximumCacheSize(int size)
Sets the maximum size of the internal cache of the
IlvJDBCTableModel . |
void |
setResultSet(ResultSet resultSet)
Initializes the
IlvJDBCTableModel with the given
java.sql.ResultSet . |
void |
setThreadingEnabled(boolean value)
Sets whether or not threading must be used to compute the internal cache.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
public IlvJDBCTableModel()
IlvJDBCTableModel
. It should then be initialized
with one of the following methods:
setConnection(Connection, String, Object[])
,
setConnectionParameters(String, String, String, String, String, Object[])
or setResultSet(ResultSet)
.public IlvJDBCTableModel(Connection connection, String query) throws SQLException
IlvJDBCTableModel
from a
java.sql.Connection
and an SQL query.connection
- The connection to the databasequery
- The query to be executed to fill the table model. In this query,
every parameter should be validated, to prevent SQL injection
attacks.SQLException
- if the IlvJDBCTableModel
is unable to perform the
query.public IlvJDBCTableModel(Connection connection, String query, Object[] queryParameters) throws SQLException
IlvJDBCTableModel
from a
java.sql.Connection
and an SQL query.connection
- The connection to the databasequery
- The query to be executed to fill the table model, with a question
mark placeholder for each parameter.queryParameters
- Parameters of the query.SQLException
- if the IlvJDBCTableModel
is unable to perform the
query.public IlvJDBCTableModel(String databaseURL, String user, String passwd, String driverName, String query) throws SQLException
IlvJDBCTableModel
from a set of
JDBC parameters.databaseURL
- the database URLuser
- the user used to access the databasepasswd
- the user passworddriverName
- the driver used to connect the database, can be null
if the driver is already registered.query
- The query to be executed to fill the table model. In this query,
every parameter should be validated, to prevent SQL injection
attacks.SQLException
- if the connection to the database cannot be done.public IlvJDBCTableModel(String databaseURL, String user, String passwd, String driverName, String query, Object[] queryParameters) throws SQLException
IlvJDBCTableModel
from a set of
JDBC parameters.databaseURL
- the database URLuser
- the user used to access the databasepasswd
- the user passworddriverName
- the driver used to connect the database, can be null
if the driver is already registered.query
- The query to be executed to fill the table model, with a question
mark placeholder for each parameter.queryParameters
- Parameters of the query.SQLException
- if the connection to the database cannot be done.public IlvJDBCTableModel(ResultSet resultSet) throws SQLException
IlvJDBCTableModel
from a
java.sql.ResultSet
.resultSet
- The result set that will be used to fill the table model.SQLException
- if the ResultSet
cannot be accessed.public final void setConnection(Connection connection, String query) throws SQLException
IlvJDBCTableModel
with a
java.sql.Connection
and an SQL query.connection
- The connection to the database.query
- The query to be executed to fill the table model. In this query,
every parameter should be validated, to prevent SQL injection
attacks.SQLException
- if the IlvJDBCTableModel
is unable to perform the
query.setConnection(Connection, String, Object[])
public final void setConnection(Connection connection, String query, Object[] queryParameters) throws SQLException
IlvJDBCTableModel
with a
java.sql.Connection
and an SQL query.connection
- The connection to the database.query
- The query to be executed to fill the table model, with a question
mark placeholder for each parameter.queryParameters
- Parameters of the query.SQLException
- if the IlvJDBCTableModel
is unable to perform the
query.public final void setResultSet(ResultSet resultSet) throws SQLException
IlvJDBCTableModel
with the given
java.sql.ResultSet
.resultSet
- the ResultSet
used to fill the table model.SQLException
- if the ResultSet
cannot be accessed.public final void setConnectionParameters(String databaseURL, String user, String passwd, String driverName, String query) throws SQLException
IlvJDBCTableModel
with a set of JDBC
parameters.databaseURL
- the database URLuser
- the user used to access the databasepasswd
- the user passworddriverName
- the driver used to connect the database, can be null
if the driver is already registered.query
- The query to be executed to fill the table model. In this query,
every parameter should be validated, to prevent SQL injection
attacks.SQLException
- if the connection to the database cannot be done.setConnectionParameters(String, String, String, String, String,
Object[])
public final void setConnectionParameters(String databaseURL, String user, String passwd, String driverName, String query, Object[] queryParameters) throws SQLException
IlvJDBCTableModel
with a set of JDBC
parameters.databaseURL
- the database URLuser
- the user used to access the databasepasswd
- the user passworddriverName
- the driver used to connect the database, can be null
if the driver is already registered.query
- The query to be executed to fill the table model, with a question
mark placeholder for each parameter.queryParameters
- Parameters of the query.SQLException
- if the connection to the database cannot be done.public ResultSet getResultSet()
ResultSet
used internally by this
IlvJDBCTableModel
to query the database. If the
IlvJDBCTableModel
has not been yet initialized this method may
return null
. If the caching operation is finished the returned
ResultSet
may be closed.protected void finalize() throws Throwable
IlvJDBCTableModel
resources are released.public final void setMaximumCacheSize(int size)
IlvJDBCTableModel
. The default value is
Integer.MAX_VALUE
which means the entire
ResultSet
will be cached in the IlvJDBCTableModel
. There are typically two reasons for which it would be set to smaller
values:
ResultSet
is huge and memory
need to be saved.
ResultSet
implementation of the database driver is
already managing a cache.
ResultSet
is
of type ResultSet.TYPE_FORWARD_ONLY
whatever is the maximum
cache size, a full caching will be performed. Calling this method will
erase the cache and so in order for this new value to be taken into account
and the model to be workable a new connection must be performed (
setConnection(Connection, String, Object[])
,
setConnectionParameters(String, String, String, String, String, Object[])
, setResultSet(ResultSet)
after calling this method.size
- the size of the cachegetMaximumCacheSize()
public final int getMaximumCacheSize()
IlvJDBCTableModel
. The default value is
Integer.MAX_VALUE
which means the entire
ResultSet
will be cached in the IlvJDBCTableModel
. There are typically two reasons for which it would be set to smaller
values:
ResultSet
is huge and memory
need to be saved.
ResultSet
implementation of the database driver is
already managing a cache.
ResultSet
is
of type ResultSet.TYPE_FORWARD_ONLY
whatever is the maximum
cache size, a full caching will be performed.setMaximumCacheSize(int)
public final void setThreadingEnabled(boolean value)
JTable
. The default values is false
.value
- threading enabled or notpublic final boolean isThreadingEnabled()
JTable
. The default values is false
.setThreadingEnabled(boolean)
public final void join() throws InterruptedException
IlvJDBCTableModel
caching thread to be finished. This is
particularly useful in case of full caching (i.e.
getMaximumCacheSize()
returns Integer.MAX_VALUE
) to
not ask for values before they have been cached. Moreover this method does
nothing if isThreadingEnabled()
returns false
or when
the caching mechanism is not activated (i.e. getMaximumCacheSize()
does return 0
.InterruptedException
isThreadingEnabled()
public int getRowCount()
TableModel.getRowCount()
public int getColumnCount()
TableModel.getColumnCount()
public Object getValueAt(int rowIndex, int columnIndex)
TableModel.getValueAt(int, int)
public String getColumnName(int columnIndex)
columnIndex
.getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
public Class<?> getColumnClass(int columnIndex)
JTable
to set up a default renderer and
editor for the column.getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
columnIndex
- the index of the columnprotected void releaseResources() throws SQLException
IlvJDBCTableModel
. This
method is called when the IlvJDBCTableModel
has finished the
caching operation. Which means this method is called only when a full
caching is performed. The default implementation is closing the
java.sql.ResultSet
used by the table model except if it has
been explicitly set by the user by calling
IlvJDBCTableModel(ResultSet)
or
setResultSet(ResultSet)
. It can be overridden to
close other resources or not close the ResultSet
.SQLException
getMaximumCacheSize()
,
getResultSet()
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.