There really is no way to recognize him, my friend. But I myself, using the method to find out if it is empty or not.
First, by creating a JTable , set the default value to 0 . If you want to use JTable , do a JTable with data that returns a score from the database. Therefore, if not, data.getRowCount() will return 0 again. So, you will find out if the JTable empty or not.
try (ResultSet rs = st.executeQuery(query)) { int colcount = rs.getMetaData().getColumnCount();//get the row count in the database DefaultTableModel tm = new DefaultTableModel(); for (int i = 1; i <= colcount; i++) { tm.addColumn(rs.getMetaData().getColumnName(i)); } while (rs.next()) { Object[] row = new Object[colcount]; for (int i = 1; i <= colcount; i++) { row[i - 1] = rs.getObject(i); } tm.addRow(row); } jTblAd.setModel(tm); conn.close(); }
Finally, I want to say that if jTable has a head, for example: Name-Surname-Age, etc., table.getRowCount(); table.getColumnCount(); table.getRowCount(); table.getColumnCount(); not working due to jtable chapter. So, I believe that if we cannot check jTable, check the dataset that will be written to the table.
source share