File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Factory concept to provide DB transparency 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 "Factory concept to provide DB transparency" Watch "Factory concept to provide DB transparency" New topic
Author

Factory concept to provide DB transparency

Neha Yadav
Greenhorn

Joined: Aug 26, 2004
Posts: 5
Hi All

My software needs to connect to any database, whose name is provided dynamically at run time. I have java prg packaged as .jar files for kind of database which provide connection to it.

The problem is i need to present a generic interface using Factory concept which should take care of interacting with the appropriate .jar file depending upon the DB dynamically.

Could someone please tell me how this can be done?
My code needs to independent of database xml/relational and also independent of any JDBC code. I have not implemented this abstraction.

Thank you
Regards
Neha
[ August 27, 2004: Message edited by: Neha Yadav ]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Neha,

If you've already implemented your DB connectivity code then I think the optimum solution will be somewhat dependent on how you've done it.

The basic idea of a class factory is that, based on some information you supply either as a parameter or through some kind of configuration, it will manufacture that right kind of object of a given type.

If your database code (SQL & JDBC) are completely platform neutral then the only differences between databases will be the JDBC Driver and the connection string. You can abstract this further by using a javax.sql.DataSource (a Connection factory) with JNDI.

Otherwise you'll probably need to map your DAOs to the appropriate database, say in a properties file, and create a factory class which performs the lookup for the requested DAO, creating your object with something like Class.forName("com.myorg.myapp.dao.MyDAO").newInstance().

Does that make any sense?

Jules
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Factory concept to provide DB transparency
 
Similar Threads
Java application Microsoft SQL server
Doubt on using third party driver?
Data as Context Independent Concept
Use Reflection to "find" classes
Creating an Update App