Local database reading edition
Storing database result sets
Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.
Opening post
administrator · 2001-02-12 02:36:56
Question: Which is the preferred collection class to use for storing
database result sets?
Answer :
When retrieving database results, the best collection implementation to
use
is the LinkedList. The benefits include:
* Retains the original retrieval order
* Has quick insertion at the head/tail
* Doesn't have an internal size limitation like a Vector
where when the size is exceeded a new internal structure is created
(or you have to find out size beforehand to size properly)
* Permits user-controlled synchronization unlike the pre-Collections
Vector
which is always synchronized
Basically:
ResultSet result = stmt.executeQuery("...");
List list = new LinkedList();
while(result.next()) {
list.add(result.getString("col"));
}
If there are multiple columns in the result set, you'll have to combine
them
into their own data structure for each row. Arrays work well for that
as you
know the size, though a custom class might be best so you can convert
the
contents to the proper type when extracting from databse, instead of
later.
Ahimanikya Satapathy
http://www.ammu.org/kuku
Source notes
MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 5