aspose file tools*
The moose likes JDBC and the fly likes JDBC Application against multiple databases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Application against multiple databases" Watch "JDBC Application against multiple databases" New topic
Author

JDBC Application against multiple databases

jav maqbool
Greenhorn

Joined: Mar 13, 2006
Posts: 5
I am looking to write the Java application which should be able to run against multiple database namely Oracle, Sql Server and DB2, however only one at any given time. Properties file will be used to configure the database driver and connection params etc. I am looking for Tips, Pitfalls and any help to avoid the problems rather than discovering them later.

Cheers
Ankur Srivastava
Ranch Hand

Joined: May 11, 2004
Posts: 62
The first approach which I can think of is using DAO factory. So there will be a DAO factory and implementation of DAO's for different databases. But with this approach you need to ship the code (at least the class files) for three different implementation of dao's.

The other way could be to implement your API as JDBC is implemented i.e. you write interfaces then provide the implementation to the interfaces for each database and put these implementation in seperate jar files. Now depending on the database you would be using distribute the respective jar file with your application.

I would personally go for the second approach

I hope this helps.

- Ankur
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 354
hello,

I only like the first suggestion with the DAO factory.

The best solution also depends on the kind of abstraction your data layer exposes. Let's assume the typical case of a normal object-relational mapping.

The best existing solution for this kind of thing is hibernate. It solves your database portability problem and provides the implementation of the persistence layer at the same time.

Kai


Kai Witte's business website Kai Witte's private homepage Mock exam / preparation kit reviews
jav maqbool
Greenhorn

Joined: Mar 13, 2006
Posts: 5
Thanks Ankur - Certainly one way of doing it - But I was thinking more along the lines of one code fits all approach, may be ambitious or lazy whatever angle you look at it.
[ March 16, 2006: Message edited by: jav maqbool ]
Ankur Srivastava
Ranch Hand

Joined: May 11, 2004
Posts: 62
Forgot to mention that the best approach would be to go for an already available ORM tool like Hibernate. You would now write your code which is very much database independent, it is based on your configuration and settings that at run time hibernate will generate the database dependent code(queries).

This is very much similar to the second approach I had mentioned earlier but then here you do not have to write the code to access the different databases as that is provided by hiberante and is pretty much transparent to the code we would be writing.

I got htis idea while going through a Similar Topic. You might be also intereseted in visiting it!!

- Ankur
jav maqbool
Greenhorn

Joined: Mar 13, 2006
Posts: 5
Great thats more like it - it sounds interesting - I will check out this Hibernate stuff - any more help will be appreciated. Thanks both Kai & Ankur
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Application against multiple databases
 
Similar Threads
Best Database Connection Pools ?
Local mode an d remote mode
JDBC/JNDI Database Restore
Open Source application
HSQLDB and TO_DATE