my dog learned polymorphism*
The moose likes JDBC and the fly likes Database Access Class Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database Access Class Pattern" Watch "Database Access Class Pattern" New topic
Author

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?

Scenario:

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: http://aspose.com/file-tools
 
subject: Database Access Class Pattern
 
Similar Threads
DataSource issues
How To Access Objects Returned From A Helper/Utility Class?
MVC2 outside servlet for testing
Must Restart Tomcat to Aquire A Connection From The Pool
Please Help! I Have Worked On IT For Days.