• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Factory concept to provide DB transparency

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
[ August 27, 2004: Message edited by: Neha Yadav ]
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
create, convert, edit or print DOC and DOCX in Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!