• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

fetch the records from cache

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
say i have emp table

eno ename sales
1 david 1100
2 lara 200
3 james 1000
1 david 1200
2 lara 5400
4 white 890
3 james 7500
1 david 1313

eno can be duplicate

when i give empno is 1

i want to display his sales i.e 1100,1200,1313

first time i will go to database and fetch the records

but next time onwards i dont go to database; i will fetch the records from cache;

i thought doing it using hashmap or hasptable ;both those two don't allow duplicate values(empno has duplicate values);

How to solve this problem.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both those collections will allow duplicate values. They won't however support duplicate keys. Your table doesn't have a PK - which is poorly modelled, but that's a side issue. You might be better creating an Employee object which holds your three values and store collections of them in a HashMap, keyed of empno.
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i put eno as key;hashmap cant take duplicates naa;in my emp table i have eno has duplicate values
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In SQL what you are trying to do is:

What that retruns is a collection of records where the empno value == [value]. To represent the same sort of data in a collection, you need to create an object to hold the record values (the Employee object I suggested). This way you can go through the RecordSet creating Employee objects for each record in your table. For each empno (i.e. distinct employee) you could create an ArrayList (or whatever collection takes your fancy) and store only those Employee objects for a particular employee. Then add the ArrayList to your HashMap (please don't use Hashtable unless you absolutely require a synchronized collection), keying it on empno. Now you have a collection which represents the results you would see if you ran this SQL:
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Intermediate forum...
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic