• 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

returning a ResultSet?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am debating whether or not to create a function that will return a ResultSet. Is this something that is acceptable or is it bad practice?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It shouldn't be a problem as long as you are sure that you close the ResultSet after using it.
But, I think a better ways is to convert the ResultSet to a List or array of objects that encapsulate the data that is in the ResultSet and return that List (or array). That way, the client class does not have to care about the details of ResultSet closing and it even doesn't need to know that the data is coming from a relational database.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
things can get very messy if you start to throw ResultSets around, especially between classes or on high traffic applications. Your objective should be to minimize stress on the database, so you should have a "get in, and get out" type attitude. As mentioned above, store it in an object/collection that best suits your needs to process the results.
Jamie
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic