Hi, 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. Thanks Neha
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!
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Joined: Jul 13, 2001
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 Bye Neha
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 chz, mpr
Joined: Jul 13, 2001
you looks like a real java Guru. Thanks Reddy Garoo
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.