java.sql.ResultSet -> Vector
I'm currently working on a test project (i.e. just to see if I can do it) that takes a ResultSet from one class, cycles through it to create a vector (technically a vector of vectors) and then uses the vector(s) to populate a JTable.
It works fine but I've been looking for a more elegant way of building the vector - does anyone know of a more OOP-friendly way of accomplishing this? Right now I'm iterating through the ResultSet and adding each value to the vector. This seems to be kinda old-skool and not very effecient. Here's a code snippit (the important bits at least):
I haven't tried it yet but I'm thinking that I might be able to recast the ResultSet into something a bit more generic. Either that or I can create a new class which extends ResultSet and add my own methods (getRowData(int x) or something).
TIA!
It works fine but I've been looking for a more elegant way of building the vector - does anyone know of a more OOP-friendly way of accomplishing this? Right now I'm iterating through the ResultSet and adding each value to the vector. This seems to be kinda old-skool and not very effecient. Here's a code snippit (the important bits at least):
/*
* tableData is a ResultSet with 23 records inside. Each record has 12 fields/columns.
* rowCount is an integer used to hold the total number of rows as 23 is not static.
* colCount is an integer that was set in a different method which was build from the ResultSetMetaData.
* row is a Vector which contains a single row
* rowData is a vector which contains a collection of row vectors.
*/
tableData.last();
rowCount = tableData.getRow();
tableData.first();
System.out.println(rowCount);
rowData = new Vector(rowCount);
for(int x = 1; x <= rowCount; x++){
row = new Vector(colCount);
for(int y = 1; y <= colCount; y++){
System.out.println("Row number " + x + " Column number " + y + " - Value = " + tableData.getString(y));
row.add(tableData.getString(y));
System.out.println("Column added to row");
}
rowData.add(row.clone());
tableData.next();
}
tableData.close();
I haven't tried it yet but I'm thinking that I might be able to recast the ResultSet into something a bit more generic. Either that or I can create a new class which extends ResultSet and add my own methods (getRowData(int x) or something).
TIA!
