• 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

JDBC Application objects (query each time)?

 
Greenhorn
Posts: 24
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a project that is going to query a DB for exercises. The way it's currently going to be laid out is that you will come to a main window that has selection buttons for which type of exercise you want. Then that will bring up a list of exercises in that category. Finally, once a selection is made from the list it will bring up a detailed window showing an image (actually an animation) and text detailing how to perform the exercise. The user will be able to create new exercises if desired but the DB will be loaded with some standard exercises.

Anyway, I'm wondering if there is a best practice for something like this. I am not sure whether I should create all of the exercise objects first and store them in a list where the GUI can query them or if I should query them directly from the database and create a new object each time an exercise is selected.

I would think you would want to query the DB so it's less of a hassle to update the lists when a new exercise is added or an existing is edited. But at the same time I feel that may be wasted processing constantly querying the DB whereas I could just query the database in one big chunk and create all of the objects at once. Then if they edit or create an exercise I'll just append it to or edit the current list.

So, to sum it up, should I preload objects from a database, create new objects each time or both?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest that you are indulging in what's known as "premature optimization" in the computer business. Don't spend a lot of time trying to guess how well two choices will perform. The best practice in this case is to write the simplest possible code and try it out. If it's too slow or if it uses up all of your memory, then you can start trying to improve it.
 
Geoff Berl
Greenhorn
Posts: 24
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:I'd suggest that you are indulging in what's known as "premature optimization" in the computer business.



Shoot, sorry, I do this a lot. Since I do this a lot you'd think I'd be able to tell that I am doing it but I don't. You make a very good point, I will go ahead and code away, ask questions later.
 
Proudly marching to the beat of a different kettle of fish... while reading 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