I need to use an embedded database in my java application that will be run in a Linux device. The application uses Hibernate and derby database. This is not a Android application. Due to slow performance of the database, we are looking for a better embedded database framework. Looking at all the options, H2 seems to be better than SQLite as there is no cross-compilation involved and no JNI interface to build. So, why isn't there a more usage of H2. Are there any drawbacks or issues that I am not aware of.
-
5SQLite is used more often than H2 because SQLite is available in iPhones (iOS), Android, and so on. H2 is used a lot for embedded Java applications, but there are just not _that_ many embedded Java applications. – Thomas Mueller Apr 19 '17 at 04:20
2 Answers
I recently switched from H2 to SQLite because of database corruptions in the H2 mv store.
If the application is not shutdown properly, or in case of unexpected reboots, the H2 database stored on a file using the MV store (the default) can get corrupt, and you can't restore data.
SQLite is much more robust to corruption.
Speed wise H2 was much faster in my case. With SQLite transactions are particularly costly, so you should prefer doing bulk operations within transactions or via batches.
As for cross compilation, you can use the jdbc driver from xerial which ships with all the native binaries precompile : https://github.com/xerial/sqlite-jdbc

- 3,613
- 1
- 23
- 40
-
5I can confirm that database corruption is indeed an issue with H2, especially when users routinely simply kill your app, because they believe nothing can go wrong when they do so. – Hendrik Jun 09 '22 at 08:38
The SQLite library is implemented in C, so it indeed needs (cross-)compilation and a JNI interface. However, SQLite is so widely used that it is likely that the SQLite interface already exists (as part of your language's runtime, or as a JDBC driver), and that using it is simpler than explicitly adding H2 to your project. (This might not actually be true in your specific environment.)
If you're looking to speed up your application, you have to measure yourself.

- 173,858
- 17
- 217
- 259