Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable - How do I re-load the table with different set of data  RSS feed

 
Jini Varghese
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am retrieving the data from a Table using JDBC. I don't have any problems loading it first time. How do I load the JTable with different set of data? Should I use the TableModel? Or If I refresh the Vectors (rows, columnHeads), would it work?
Here is the code :
sb is a SQL class written by me to handle the JDBC stuff.
sb.setResultSet("SELECT * FROM Categories" );

//columnHeads=null;
try{
columnHeads = sb.getColumnHeads(sb.getResultSet());
}

catch(SQLException exx){

}
//rows=null;
try{
rows = sb.getRowsInVector(sb.getResultSet());
}

catch(SQLException exx){

}

jTable2 = new JTable(rows, columnHeads );

scroller = new JScrollPane(jTable2);
scroller.setSize(new java.awt.Dimension(460, 370));
scroller.setVisible(true);
scroller.setLocation(new java.awt.Point(250, 100));
getContentPane().add(scroller);


sb.close(); // close the database connection

Thanks in advance!
[This message has been edited by Jini Varghese (edited March 10, 2001).]
 
David Freels
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the default table model and use the setDataVector method. This will reload the data in the JTable.
Hope this helps.
David
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!