Interested in how to display a dynamic table from the database on the GUI - form. Used the interface "AbstractTableModel".

public void ADDJ(DBConnection connect, String nametable) { ResultSet resultSet = connect.query("SELECT * from " + nametable);// poluchaem stroki s tablici list.clear(); try { final int koll = resultSet.getMetaData().getColumnCount(); System.out.println("Column count = " + koll); columnCount = koll; for(int i=1; i<=koll; i++) { ResultSetMetaData meta = resultSet.getMetaData(); String column = meta.getColumnName(i); System.out.println("Column[" + i + "] = " + column); // String [] row = {column, " ", " ", " ", " "}; // addData(row); } while (resultSet.next()) { for (int ii = 1; ii <= koll; ii++) { //row[ii - 1] = resultSet.getString(ii); String [] row = {resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5)}; // String[] row = {resultSet.getString(ii)}; addData(row); } } } catch (SQLException e) { e.printStackTrace(); } } 

When I try to access the array index to input the data, it starts to crash.

  • As a GUI FX or Swing? I would advise all the same to look in the direction of ORM. for example, in FX, the table can be configured so that it can be directly fed the result of the query from the table, without any conversion. - Riĥard Brugekĥaim
  • @ Riĥard Brugekĥaim, Swing, I would gladly try to do something else, but I do not have sufficient skills, I only teach). Since I started the project with Swing, it's better for him. Or hard implemented? - Baffik
  • one
  • @Tsyklop Thank you, you almost figured it out, I was pretty close.)). I could not understand where you have the list with the variable "Rows" - I thought maybe the library should download. Until I saw the file with the implementation. I understood the point, I think I cope. - Baffik

0