- Use some Java Persistent API, if you can (like Hibernate, JOOQ or JSQLParser).
- Use jdbc functions whenever possible. Do you want to retrieve a list of tables? Do it with getMetaData(). If you do it with, for example, information_schema, then it's not going to work on Oracle.
- If you have to directly write SQL, limit yourself to subset of commands supported by MySQL - only a few relational databases support a smaller subset of SQL commands (the only one I can think of is SQLite). Hence, if your application works on MySQL, it's likely to be more or less portable to any other database.
- Build good unit tests. You are going to need them.
neděle 15. února 2015
How to write database agnostic java application
There are several best practices: