0

https://i.stack.imgur.com/E4lYz.png

DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
     Vector<String> v1 =new Vector<String>();
     Vector<String> v2 =new Vector<String>();
     Vector<String> v3 =new Vector<String>();
     Vector<String> v4 =new Vector<String>();
     Vector<String> v5 =new Vector<String>();
     Vector<String> v6 =new Vector<String>();
     Vector<String> v7 =new Vector<String>();
     Vector<Vector> data = new Vector<>();

  while(rs.next()){
   Column = rs.getFieldNames();
     // v55.add(u);
      v1.addElement(rs.getField("Project ID"));
      v2.addElement(rs.getField("Duration (Weeks)"));
      v3.addElement(rs.getField("Due date"));
      v4.addElement( rs.getField("Resource 1"));
      v5.addElement( rs.getField("Resource 2"));
      v6.addElement( rs.getField("Resource 3"));
      v7.addElement( rs.getField("weight  (1-5)"));
         }  

   data.addElement(v1);
   data.addElement(v2);
   data.addElement(v3);
   data.addElement(v4);
   data.addElement(v5);
   data.addElement(v6);
   data.addElement(v7);

   for (int i = 0 ; i<Column.size();i++){
        model.addColumn(Column.get(i), data.elementAt(i));
   }
camickr
  • 321,443
  • 19
  • 166
  • 288
  • Don't create the Vectors in advance. While looping through the ResultSet you create a Vector. Then you add each element to the Vector. Finally you invoke the `addRow(...)` method of the DefaultTableModel to add the Vector to the model. See: https://stackoverflow.com/a/55635012/131872 for a basic example. – camickr Sep 22 '20 at 02:42
  • how to make ResultSet create a Vector. Then add each element to the Vector ..... h want to see Example .... thank you – AmeeR mhmed Sep 22 '20 at 13:11
  • I did give you an example. What don't you understand about the example? – camickr Sep 22 '20 at 13:47
  • I want when i read any file excel show all data in sheet at excel file in jtable.... now this need to create vector for every column in sheet at excel file .... the problem i don't to create object of vector from code ...i want dynmicaly – AmeeR mhmed Sep 22 '20 at 14:42
  • Your code appears to be using a ResultSet. I gave you code that shows how to create a table model dynamically with data from the ResultSet. – camickr Sep 22 '20 at 20:29
  • thank you ...but i use Recordset rs= connection.executeQuery(strQuery); – AmeeR mhmed Sep 23 '20 at 03:08
  • thank you ...but i use Recordset rs= connection.executeQuery(strQuery); I used ResultSet to fetch data from the excel file but it does not get the data from the excel file Is there a way to use Recordset to fetch data dynamically? to create a table model dynamically with data Because ResultSet does not execute the query command in the fillo-1.21 package Connection conn = fillo.getConnection(strQuery) – AmeeR mhmed Sep 23 '20 at 03:17
  • I have no idea what the Recordset is. That is not a class in the standard JDK. If you are using a 3rd party API then you need to read there API to understand how to read the excel file. My answer assumes you know how to read the data from the file and then you simply process the data one row at a time as you read the data. – camickr Sep 23 '20 at 04:30

0 Answers0