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