Hi, I am connecting to the database. I am outputting the data via rs.next (), everything is ok. I wrote a function to display values in a table and get an error every time.
ArrayIndexOutOfBoundsException: 0> = 0
I understand that the error with the index, but that just did not change nothing happens
public JTable getTable(String nameTbl){ JTable tbl = new JTable(); String querty = "select * from " + nameTbl; try { rs = st.executeQuery(querty); rsmd = rs.getMetaData(); int countCol = rsmd.getColumnCount(); int countRow = rs.getRow(); javax.swing.table.DefaultTableModel dtm = new javax.swing.table.DefaultTableModel(); dtm.setRowCount(0); int cC = 0; int cR = 0; int n = 0; String[] nameColumn = new String[10]; int c = 0; for(int i = 1; i <= rsmd.getColumnCount(); i++){ nameColumn[c] = rsmd.getColumnName(i); c++; } while(rs.next()){ dtm.setRowCount(dtm.getRowCount() + 1); if(cC < countCol){ dtm.setValueAt(rs.getString(nameColumn[cC]), cC, cR); cC++; } if(cC == countCol) cC = 0; cR++; } tbl.setModel(dtm); } catch (SQLException ex) { System.out.println("Error " + ex); } return tbl; } error location
dtm.setValueAt(rs.getString(nameColumn[cC]), cC, cR);