wood burning stoves 2.0*
The moose likes Servlets and the fly likes RecordSet Vs. Hash table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RecordSet Vs. Hash table" Watch "RecordSet Vs. Hash table" New topic

RecordSet Vs. Hash table

Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
I have to display some values from the database in my JSP. I'm looping on my RecordSet to dispaly the values. My manager is suggesting to transfer the records in a hash table and iterate on that and show the value, he says that it's a better way to do it , though he doesn't know the why ?
Does anybody has any idea on this.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Since you are the Java developer, and not your manager, explain to your mgr. why using a hashtable does not really buy you any thing. Unless he has a specific reason for wanting you to put it in a Hashtable(not even an ArrayList!). Loop through the resultset and do your thing!


So much trouble in the world -- Bob Marley
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
Hi Bosun Bello,
Thanks for your reply, you know that some people have to prove they are smarter, though for no reasons. Here's the same kind of stuff with my manager.
Suggestions please regarding resultset VS. Hashtable

Manjunath Reddy
Ranch Hand

Joined: Jul 26, 2001
Posts: 60
Well...lemme think of a few pointers to offset the hashtable paradigm..in no particular order,
1. If the resultset returns too many results, there will be a memory constraint leading to automatic hashtable rehashing, which degrades performance.
2.Unlike the new collections framework, access to hashtables are synchronized. What this means is, if you are using EJB framework then all the objects that are contained in hashtable have to be serializable.
3.If the resultset has int datatype you will have to create an Integer out of the int,every time u put or retrieve something from the Hashtable.
Since object creation is a costly process, any manager would agree to avoid this Integer object creation just for the purpose of putting things into the HashTable(Although there are workarounds to this by extending Hashtable class).

4.On the presentation front(JSP), while iterating thru the objects from the hashtable, you need to check whether an object is present thru .containsKey method to prevent java.lang.NullPointer exceptions..thereby adding to the load. Also one has to make sure that no null objects get added into the Hashtable(results again in the infamous Null Pointer exception).
Hope this gives u some moolah to be smarter
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
you looks like a real java Guru.
Thanks Reddy Garoo
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Also with using a Hashtable you will most likely lose any "ordering" of the data contained in the record set.
ie. when you are re-iterating back through the Hashtable, it will not necessarily be in the same order that you "put" the data.
Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
Thanks Swan.
I agree. Here's the link: http://aspose.com/file-tools
subject: RecordSet Vs. Hash table
Similar Threads
Hash Table - Sychronization
transfer a set of records(.mdb file) from client to server
Doubt in Hash Map and Hash Table
What is wrong with this code
why rowset exhausted error coming?