• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList output from Database

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an output that I get from my Oracle database where it takes parameters from form entries and queries the database. It list the records where it works with an ArrayList to get the output. Everything works great but was wondering if there is a more efficient way to do this?

 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You can use single arraylist which contains the dto/vo objects.
e.g


where ever you wanna access it
...


This will solve your problem and the code will be easier to maintain. Here you are using some valueable patterns also which you need to findout as i am not telling you.


[BPSouther: Added code tags]
[ July 24, 2007: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not really sure what you're doing with your code.
The calls to getParameter suggest that you're only dealing with one person.
If so, I don't know why you need to store the fields in array lists.
Or.. is this a search type page that shows all people with first name 'Bill' etc...?


In any case, I prefer to use either an array of row beans or a nested list of lists. In this case, the row bean would have firstName, lastName, and city properties. While iterating through the resultset, build a row bean for each record, populate it, and then add it to the list. To me this is a more logical way to group records/objects than in parallel vertical arrays or lists.

When you say 'efficient' did you mean CPU efficiency or maintenance efficiency?
[ July 24, 2007: Message edited by: Ben Souther ]
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, both your posts are really helpful.


In any case, I prefer to use either an array of row beans or a nested list of lists. In this case, the row bean would have firstName, lastName, and city properties. While iterating through the resultset, build a row bean for each record, populate it, and then add it to the list. To me this is a more logical way to group records/objects than in parallel vertical arrays or lists.



The below is like what I am now using thanks to you guys, and I assume this example of Data Transfer Objects is what you mean by iterating through the resultset and building a row bean for each record and populating and adding it to the list? I want to make sure so I can understand the terminology and how DTO work.




Or.. is this a search type page that shows all people with first name 'Bill' etc...?



Yes this is a search type page.
[ July 24, 2007: Message edited by: Joseph Smithern ]
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes you are right this is DTO.
 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, this is all now "starting" to make sense to me and need just one final clarification on this part:


This translates as DTO (name of destination class) casting the recordList object reference where it allows me to take a value of DTO type and "cast" it to another type, in the sense of molding or reforming the recordList object?
Which in this case the DTO type is casting the recordList.get(i) object to a DTO type which uses the DTO getName() method to fetch the value?
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, buddy i am taking out the object from arraylist like
recordList.get(i)
type casting into its class type in your case DTO
and lastly calling the getter method on the DTO object

and you need to iterarte over arraylist to get each record

for avioding type casting you can use genrics of jdk 1.5



one thing more i like to mention here is in your arraylist each record will be stored as object which is ORM.

Now some more to read right? ;)
[ July 25, 2007: Message edited by: subodh gupta ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic