• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with HashMap logic  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ,

I have something like this in database.

I have two columns with Name and city .

I have written a Database program using JDBC and written two select statements (Gettting Data in two ResultSet for each column)

Now please tell me how can i load this data into my HashMap (Name/ value Pair ).

Thank you .
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why two select statements? In one select, you can get values in resultset by their column no. After retrieving both values put them in map within same iteration.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya , thank you .

I will use single statement only . But how to put this data into hashmap (any sample code)
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, create hashmap object before iterating over resultset, then inside the loop, get name and city in some variable, call put(name, city) of hashmap.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much .

Now I can do this .
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just out of curiosity, is this for work?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for fun
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!