neděle 15. února 2015

How to write database agnostic java application

There are several best practices:
  1. Use some Java Persistent API, if you can (like Hibernate, JOOQ or JSQLParser).
  2. 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.
  3. 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.
  4. Build good unit tests. You are going to need them.

Žádné komentáře:

Okomentovat