This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes OOD Q re: building object from a RDMS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "OOD Q re: building object from a RDMS" Watch "OOD Q re: building object from a RDMS" New topic

OOD Q re: building object from a RDMS

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
I'm writing a webapp and I'm working on the data access piece right now. I'm basically using the data access pattern which I get and works well, but my question is, what is the best way to retrieve data and built a set of objects from a DB?

right now if I have a Widget class with thing1 and thing1 as attributes. My WidgetDAO class has the object itself, plus setPrimaryKey(), getPrimaryKey(), storeData() and some other methods.

But if I want to go into the DB and get all widgets where thing1 == someValue, is it best to have a WidgetReader class with a public static ArrayList<Widget> getWidgets() method?

that's how I did it last time, and it was ok, but I was wondering if there are some other design ideas out there I should know about.
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30076

That's fine. As your application gets larger, you can use an object relational mapping framework such as Hibernate. It prevents you from having to write the code yourself for database access.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
It is sorta covered in the JavaRanch Style Guide.
subject: OOD Q re: building object from a RDMS
Similar Threads
Use of Factory pattern in a colocated architecure
NX Contractors: getting remote implementation to return a reference
Mediatortype javaprog requiring solution
How to expand single user WebApp to multiple users
J2EE/Struts 1.1 pattern tips