How retrieve the more than one row from database into hastable using java
Hashtables
Collapse
X
-
-
Hi,Originally posted by doniraviHow retrieve the more than one row from database into hastable using java
I am not an expert in Java but I have a basic idea on Hashtables and how to use them which I would like to share with you,
As you might already know a Hashtable contains key-value pairs and it maps the keys to the values.Any non-null 'object' can be used as a key or a value.
So when you retrieve records from your backend-table in a ResultSet what you can do is say pass that ResultSet as an argument to some function having a return type as 'Hashtable'.
In this function you create a new empty Hashtable.
Now you can first store your ResultSet-record in say some object and then you can add that object to the hashtable as a 'value' and you can keep the primary- key of that record as the 'key' of this hashtable-entry() if you like.
Finally after adding all records one by one to the Hashtable until the end of the ResultSet your function can return it to the calling code.
Hope this helps!Comment
Comment