添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
幸福的手术刀  ·  [Interest] ...·  6 天前    · 
鼻子大的苹果  ·  记录QT QSqlDatabase ...·  6 天前    · 
彷徨的哑铃  ·  NpgsqlException:dotnet ...·  1 年前    · 
愉快的钱包  ·  使用Python ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

SQLite 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, 2017 at 4:20

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.

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

I 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 9, 2022 at 8:38

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .