thanx to Cris and Glenn for their info and links.
After some research, ArrayList is the way to go as it offers the best
flexibility and performance cost.
For those wanting to know more read below:
At the JSPInsider web site I found an intersting article on Java
Optimization
http://www.jspinsider.com/jspbuzz/2000/buzz_08_15_2000.view#topic
* Significant performance trade-offs exist for the various object
storage options.
-An array is at least 4 times faster than an ArrayList.
-An ArrayList is at least 50% faster than using a Vector.
-Don't use Vectors or Hashtables! Using a Vector or Hashtable will
just slow your code down and give you a headache due to
synchronization issues.
-A HashSet is faster than a TreeSet (but both are much slower than
an ArrayList)
So if I can use an array, I'll use an array or a set of arrays. The
only problem with arrays is that they are fixed in size, while Vectors
or Hashtables can be changed.
BUT this link
http://www.jspinsider.com/beans/snippets/database/HashTables.txt
has the following info:
// Maintaining a database connection over the web is expensive. By
// dumping the data into a hashtable you can minimize the amount of
// time you stay connected to your database. Also by storing the data
// in a hashtable offers flexible way to pass your data from
// object to object.
AND
////////////////////////////////////////////////////////////////////////
//
// IMPORTANT!
// Please note the following.
// -If you are using Java 1.2 or better, You should use an
ArrayList!
// An arraylist is much much faster than a Hashtable.
// -You should only use a Hashtable or Vector when you want java
1.1.x compatibility
// -If you are using large amounts of data, this will be a slow
solution
// and you should seriously consider upgrading to Java 1.3 and use an
ArrayList.
//
////////////////////////////////////////////////////////////////////////
//
So now I have to figure a solution using ArrayLists. If anyone has code
examples, I'd appreciate it, or else I'll work it out myself by creating
a utility bean.
For more info on ArrayLists have a look at:
http://java.sun.com/j2se/1.3.0/docs/api/java/util/ArrayList.html
There is also a good presentation at
http://www.nejug.org/2000/sept00_slides/javaperf.htm
Some summary comments include:
When creating an ArrayList or a Vector, the default size is 10 elements.
The re-growing of ArrayList (increases by 50%) and Vectors (doubles) is
expensive, thus if you know the size in advance, or you know its going
to be bigger than 10, then declare the size bigger then 10 when you
create the ArrayList.
So when you get the recordset, the number of columns returned is easy
via the rs.getMetaData().getColumnCount() but are there any methods to
get the number of rows returned, apart from doing a SELECT COUNT(*) FROM
TABLE, or maybe I am worring about too much???
Any comments or disagreements are welcome
Thanx, Andrew
:ab
----
Andrew Bruno
http://www.xenon.com.au
----
-----Original Message-----
From: Glenn Wearen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 6 September 2001 1:27 AM
To: [EMAIL PROTECTED]
Subject: Re: RECORDSET TO array OR VECTOR
> >From: Andrew Bruno <[EMAIL PROTECTED]>
> >Reply-To: A mailing list about Java Server Pages specification and
> >reference <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: RECORDSET TO array OR VECTOR
> >Date: Wed, 5 Sep 2001 14:36:09 +1000
> >
> >Hello,
> >
> >I was wondering if anyone knows of any docs, or can give
> some ideas of
> >the best way to convert a recordset into an array or vector
> so that the
> >data may be referenced many times, even though the
> connection is closed.
//make each individual resultset a vector tmp_vct1 and put it into
another
vector tmp_vct2
Vector tmp_vct2 = new Vector();
while(res.next){
Vector tmp_vct1 = new Vector();
tmp_vct1.addElement(1) = res.getString('column name or index')
...
tmp_vct1.addElement(n) = res.getLong('column name or index')
tmp_vct2.addElement(tmp_vct1);
}
//when extracting the results later...
for(int i=0; i<tmp_vct.size();i++){
Vector tmp_vct3 = (Vector)tmp_vct1.elementAt(i)
out.println((String)tmp_vct3.elementAt(1));
out.println((Long)tmp_vct3.elementAt(1));
}
There might be better ways to do this such as using the Map object but I
havn't used it.
Glenn
> >
> >ON a side note, does anyone have information on storing data into
> >javascript arrays, so that there is no need to do a server
> request. i.e.
> >from server side recordset to javascript array, but this is not that
> >important yet.
> >
> >Thanks, Andrew
> >
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets