I have worker for fill the jtable from resultset like below;
public class WorkerFillTable extends SwingWorker {
I would recommend you to use a subclass of AbstractTableModel and override the getColumnClass method to set the correct data type for the JTable.
public class CustomTableModel extends AbstractTableModel
{
@Override
public int getRowCount()
{
}
@Override
public int getColumnCount()
{
}
@Override
public Object getValueAt(int rowIndex, int columnIndex)
{
}
@Override
public String getColumnName(int index)
{
}
@Override
public Class<String> getColumnClass(int i)
{
//return the Specific class for each column based on index i
}
}
JDBCAdapter
, which extends AbstractTableModel, illustrates a typical mapping between relational database and Java data types. It may be seen here, and a complete example may be found in samples/demo/jfc/TableExample
, found among the Java SE Development Kit 8u25 Demos and Samples Downloads. In outline,
Override getColumnClass()
.
Get the column's data type
from ResultSetMetaData
.
Use switch(type)
to return the correct type-token.
Also consider a SwingWorker<Row, Row>
for finer granularity in publish()/process()
.