Monday, 9 September 2013

Populating a JTable from Access Database

Populating a JTable from Access Database

I am trying to populate a JTable with data from a database. I've tried so
many different ways and it just doesn't want to work. Currently I have a
class which returns a resultset with the entire database to my UIClass
which then uses the resultset to populate the JTable. Bellow is my method
that retrieves the resultset and then populates the JTable.
private void SetJTable()
{
int count = 0;
String boatclass, senior, under23, junior;
try
{
ResultSet results = object.AllWorldBestTimes();
DefaultTableModel model = (DefaultTableModel) Times.getModel();
model.addColumn("Boat Class");
model.addColumn("Senior");
model.addColumn("Under 23");
model.addColumn("Junior");
while(count<24)
{
boatclass = results.getString(1);
senior = results.getString(2);
under23 = results.getString(3);
junior = results.getString(4);
System.out.println(boatclass + senior + under23 + junior);
model.insertRow(Times.getRowCount(), new Object[]{boatclass,
senior, under23, junior});
count++;
}
Times = new JTable(model);
}
catch (SQLException e)
{
System.out.println("Ef");
}
}
Here is the method of retrieving data from the database:
public ResultSet AllWorldBestTimes() throws SQLException
{
DatabaseConnection connection = new DatabaseConnection();
ResultSet result = connection.SelectStatements("SELECT * FROM
WorldBestTimes");
return result;
}
there is no crash so i cannot give the stack trace, nor does it go into
the catch statement.
any help would be appreciated!

No comments:

Post a Comment