This function returns ArrayList that contains some data from DB:
public ArrayList<ArrayList<Object>> executeQuery(String host, String database,
String sqlStatement)
I need to populate JTable with this ArrayList. For instance, one of possible outputs could be (3 rows, 4 columns):
[[1, 10, 1, 2], [2, 11, 2, 1], [3, 12, 3, 1]]
I know that a table model should be created, but what if the columns are not known prior?
You can use the methods of
DatabaseMetaDatato find the number and names of a table’s attributes. You can use Class Literals as Runtime-Type Tokens to populate your data structure dynamically. Also consider programming to the interface, e.gList<List<Number>>orList<List<Integer>>.