File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes JDBC Application objects (query each time)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "JDBC Application objects (query each time)?" Watch "JDBC Application objects (query each time)?" New topic

JDBC Application objects (query each time)?

Geoff Berl

Joined: Apr 13, 2011
Posts: 24

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?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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

Joined: Apr 13, 2011
Posts: 24

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.
I agree. Here's the link:
subject: JDBC Application objects (query each time)?
It's not a secret anymore!