0

Am trying to create a JTable application but when i try to run the program in netbeans it bring an error on the addRow() and removeRow() and yet when i run it in the commandPrompt it works well what could be the problem.
below is a snippet of the code block

private void RetrieveData ()
  {
    try
    {
      int row = tmodel.getRowCount();
      while(row > 0)
      {
        row--;
        tmodel.removeRowSelectionInterval(0,3);
      }

      //execute query
      ResultSet rs = st.executeQuery("Select * from student_info");

      //get metadata
      ResultSetMetaData md = rs.getMetaData();
      int colcount = md.getColumnCount();

      Object[] data = new Object[colcount];
      //extracting data

      while (rs.next())
      {
        for (int i=1; i<=colcount; i++)
        {
          data[i-1] = rs.getString(i);
        }
      tmodel.addRowSelectionInterval(0,3);
      }
    }
    catch(Exception e) {System.out.println(e);  }
  }

Edited by Ezzaral: Added code tags. Please use them to format all code that you post.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Majestics
0
tmodel.removeRowSelectionInterval(0,3); // Seems Wrong

Because row selection can be more then total rows.

Same for Add Rows.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.