I am new to Java so please bare with me :).
I created a function that fetch the records from the table.
public ArrayList<Object> getAll() {
try {
ArrayList<Object> resultList = new ArrayList<>();
query = this.conn.prepareStatement("select * from " +
this.currentTable + this.tableClass.getWhere());
ResultSet result = query.executeQuery();
ResultSetMetaData meta = result.getMetaData();
int totalColumn = meta.getColumnCount();
while(result.next()) {
ArrayList<Object> obj = new ArrayList<>();
for (int x = 1; x < totalColumn; x++) {
obj.add(result.getObject(x));
}
resultList.add(obj);
}
result.close();
query.close();
return resultList;
} catch (Exception e) {
System.out.println("Error : " + e.getMessage());
}
return null;
}
Now, I want to display the ArrayList above in my JTable.
DefaultTableModel model = new DefaultTableModel();
ArrayList<Object> obj = this.getAll(); //call the method above
// How to insert the records above.
tableResult.setModel(model);
The problem is, there is an error while inserting an ArrayList in a JTable. I tried to cast ArrayList to Object[]
but it has also an error.
Does anybody know?