I’m looking to write a java program that has the following requirements:
- An ability to replace the database in use without changes to the code.
- I would like to do the maintanence from Java – creating the tables, views etc.
- Should be able to support complicated queries
JDBC seems like a good starting point, but it seems like the queries may be different for different DBs (for example slight syntax differences create table statements in MySQL, and MSSQL).
The idea (obviously) is to avoid writing the same code specifically for each DB, and rely on a driver to do the dirty work for me.
Is JDBC good enough? Are there other options?
JPA seems to be the optimal choice for you. It works almost-out-of-the-box. Abstracts the direct DB handling away and can be used standalone (without an application server).
JDBC is still a valid option but the development with it is not nearly as DB-agnostic as with JPA (which can be seen as an abstraction layer over JDBC).
Here is a nice example.
Most popular JPA implementations are Hibernate and Eclipselink with Eclipselink (former TopLink) being the reference implementation.