my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes Database Access Class Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Database Access Class Pattern" Watch "Database Access Class Pattern" New topic

Database Access Class Pattern

leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
This could probably go in the patterns forum...or JSP... or... here?


You want to use a PreparedStatement to issue an INSERT statement somewhere in your application.

What if at some point you want to add another field to that tablename and modify the PreparedStatement?

What does the pattern look like if I want to create a Database Class that creates the connection, creates the datasource and handles the executeUpdate() part?

Should I encapsulate the Database Class into my business object, or do you encapsulate the Database Class into an intermediary class and then encapsulate the intermediary class into your business object?

Am I looking at a Factory pattern or a Data Access Object pattern? (that's not a quiz... I'm not looking at any patterns currently.)

Or should I just leave it alone and cram everything into one method in my business object that creates the connection, datasource, etc.? Something has to get recompiled anyway... (just read the evil design patterns by Paul...)

This is where I'm at.

I'm adding a PQIDBLog property to my business object and passing the PreparedStatment to this class. Yes, this is part of a web app. I want to log certain points of the web app to a database, rather than the server log files. Is this the right approach?

Thanks, leo
I agree. Here's the link:
subject: Database Access Class Pattern
It's not a secret anymore!