Reputation: 469
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.
Upvotes: 25
Views: 32256
Reputation: 3907
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
Upvotes: 20
Reputation: 180210
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.
Upvotes: 15