• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help populating JTable from db.db

 
Randy Valadez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

else if(source == searchButton)
{
try {
Data myData = new Data("db.db");
myData.find("SA001");
System.out.println(myData.recordCount);
//I made recordCount public to use it from data class
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(this, "Database Connection Failed", "Error", JOptionPane.ERROR_MESSAGE);
}
private Object[][] rows = { {"SA001","SFO","DEN","SpeedyAir","400","Sun","13:40","20m","36"},{"RA987","DEN","ABQ","RainvilleAir","756"
,"Fri","18:20","2h10m","11"}};

String[] columnHeads = {"Flight#","Origin","Destination","Carrier","Cost","Date","Time","Duration","Seats"};
My Question:: I can hardcode the first 2 records and they display correctly in JTable. How can I populate my JTable with all records when I click my search button using my above 2 Dimensional Object array.
Thanks in Advance Randy
 
Randy Valadez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to populate all records into the
Object[][] rows instead of hardcoding them into the rows array.
Thanks in advance Randy
 
David Touchshriek
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Randy,
The method criteriaFind(String s) is supposed to populate the table for you. I would create my own table model by extending AbstractTableModel and then store the results that I get from criteriaFind(String s) in some sort of collection i.e a Vector. Then you can override public Object getValueAt(int r,int c) in yr model to display the values in the JTable.
This the very basic of the project. Maybe you need to spend more time reading about tables and data models before you begin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic