Java Embedded Databases Comparison [closed]
Asked Answered
C

18

104

I intend to develop a small (Java) application for managing my finances. I believe I need to use an embedded database, but I have no experience regarding this issue. I tried to look at some of the available products, but I can't decide which one would be more suitable for me. H2, HSQLDB, Derby and Berkeley DB seem to be good candidates, but I still don't see how they compare to each other. I appreciate your help comparing them and helping me decide which one to use.

I intend to use Hibernate for my application (unless you would recommend using DBMS-provided API), but I also want to have the ability to edit the database easily using a SQL browsing tool (modifying schema and changing data).

Thank you.

Carnarvon answered 20/1, 2009 at 20:17 Comment(5)
Without knowing what you're trying to do, it's not possible to answer this question. I suggest updating the question with info about the size of your project, how many tables you think you'll have, how many records, etc.Pyrazole
possible duplicate of Embedded java databasesCarnarvon
Comparison of modern embedded key-value stores for JavaManado
It is annoying that such good questions are closed by the Nazis. Sure, some vague questions are not suitable, but this one most certainly is. Where "Suitable" means useful for the community, rather than by some legalistic definitions.Ned
I used BerkeleyDB many years ago (like 15) in some C++ project. It was a real pain. The library really gives you not that much, as this is only key-value storage. And so low level. Avoid it unless you have a really good reason.Heteronym
B
64

Either

  • HSQLDB - Used by OpenOffice, tested and stable. It's easy to use. If you want to edit your db-data, you can just open the file and edit the insert statements.

or

  • H2 - Said to be faster (by the developer, who originally designed hsqldb, too)

Which one you use is up to you, depending how much performance and how much stability you need.

The developer of H2 has put up a nice performance evaluation:
http://www.h2database.com/html/performance.html

Bilski answered 20/1, 2009 at 22:12 Comment(0)
R
36

I use Apache Derby for pretty much all of my embedded database needs. You can also use Sun's Java DB that is based on Derby but the latest version of Derby is much newer. It supports a lot of options that commercial, native databases support but is much smaller and easier to embed. I've had some database tables with more than a million records with no issues.

I used to use HSQLDB and Hypersonic about 3 years ago. It has some major performance issues at the time and I switch to Derby from it because of those issues. Derby has been solid even when it was in incubator at Apache.

Reichstag answered 11/9, 2008 at 19:3 Comment(4)
Derby would be great if it weren't for the fact that there's so many bugs and the last update was several years ago.Bundelkhand
@Bundelkhand I can't attest to the bugs, but "...last update was several years ago" is incorrect. Relative to the time you posted your comment (August 2016): there was a release less than a year before (October 2015), a release two months after (October 2016), and a release just over a year after (October 2017 - Latest).Turnabout
Updating this comment in case someone else comes across this subject on a search. Derby most recent release was in March/2019. Here is their site info: db.apache.org/derbyRhyton
@Chris Dail Did you use derby for million records as normal database or in memory or for some caching?Lading
S
33

I needed to use Java embedded database in one of my projects and I did lot of research understanding pros and cons of each database. I wrote a blog listing pros and cons of popular embedded java databases (H2, HSQLDB, Derby, ObjectDB, Neo4j, OrientDB), you can have a look at it. I chose H2 as I thought it best suited my requirements. Link for the blog: http://sayrohan.blogspot.in/2012/12/choosing-light-weight-java-database.html Hope it helps!

Strive answered 3/2, 2013 at 22:57 Comment(0)
A
23

I'd go with H2, the performance is meant to much better than Derby. Read http://www.h2database.com/html/performance.html for more info.

Aynat answered 25/2, 2009 at 15:57 Comment(0)
S
15

HSQLDB is a good candidate (the fact that it is used in OpenOffice may convinced some of you), but for such a small personnal application, why not using an object database (instead of a classic relationnal database) ?

I used DB4O in one of my projects, and I'm very satisfied with it. Being object-oriented, you don't need the whole Hibernate layer, and can directly insert/update/delete/query objects ! Moreover, you don't need to worry about the schema, you directly work with the objects and DB4O does the rest !

I agree that it may take some time to get used to this new type of database, but check the DB40 tutorial to see how easy it makes working with the DB !

EDIT: As said in the comments, DB4O handles automatically the newer versions of the classes. Moreover, a tool for browsing and updating the database outside of the application is available here : http://code.google.com/p/db4o-om/

Stephenson answered 20/1, 2009 at 20:49 Comment(3)
Thanks. DB4O looks good for such a small project, but I believe the ability to browse and edit data outside the application is very important. Also would it be easy to handle newer versions of classes? (e.g. added/removed fields)Carnarvon
As said in my edit, there exists a tool for browsing and editing the DB outside of the application. And as Fabian said, the newer versions of the classes are automatically handeld.Stephenson
Thanks for the update. Having a browsing tool was very important to me, so thanks a lot.Carnarvon
C
13

Java DB (Sun's distribution of Apache Derby) now ships in JDK 6!

I've been wanted to do something like Jason Cohen and have been thinking this looks like the easiest way being in the JDK distro (which of last week is now a requirement for my app). Or maybe I am just lazy that way.

Consecutive answered 11/9, 2008 at 17:33 Comment(3)
You're probably right! We have a requirement to also run under Java 1.5 so this isn't an option for us.Sibeal
...I meant you were right about it being the easiest way, not right about being lazy. :-PSibeal
Java DB ships only with the Sun/Oracle implementations of the JDK. Not a standard part of Java.Capuano
S
7

We use HSQLDB in production as a "no-configuration" option for our application. It allows people to trial without the hassle of setting up a real database.

However we do not support it for normal use. The reasons are several:

  1. Slows down proportionally to the size of the data.
  2. Difficult to access outside of our app (e.g. for custom reports).
  3. Transactions / disk-sync is difficult to get right, so it's easy to lose data.

For at least (2) and (3), there are ways around it but it's difficult; it's much easier to e.g. install MySQL.

Sibeal answered 11/9, 2008 at 17:26 Comment(0)
K
7

neo4j is:

an embedded, disk-based, fully transactional Java persistence engine that stores data structured in graphs rather than in tables

I haven't had a chance to try it yet - but it looks very promising. Note this is not an SQL database - your object graph is persisted for you - so it might not be appropriate for your existing app.

Kipp answered 12/9, 2008 at 11:3 Comment(0)
K
7

HSQLDB may cause problems for large applications, its not quite that stable.

The best I've heard (not first hand experience however) is berkleyDB. But unless you opensource it, it will cost you an arm and a leg to use due to licensing...see this http://www.oracle.com/technology/software/products/berkeley-db/htdocs/licensing.html for details.

ps. berkleyDB is not a relational database in case you didnt know.

Kaufmann answered 21/1, 2009 at 10:0 Comment(2)
Oh, I didn't know Berkeley was not a relational database! Thanks a lot!Carnarvon
doesnt mean it isnt good. but i suspect its probably too good for your use considering its for something personal. also, take a look at sqlite. I think it has java bindings, but cant find it atm.Kaufmann
S
6

Good comparison tool can be found here: http://www.jpab.org/All/All/All.html

Notice also the Head to Head DBMS/JPA Comparisons

Sexivalent answered 13/11, 2013 at 22:16 Comment(0)
G
5

Most things have been said already, but I can just add that I've used HSQL, Derby and Berkely DB in a few of my pet projects and they all worked just fine. So I don't think it really matters much to be honest. One thing worth mentioning is that HSQL saves itself as a text file with SQL statements which is quite good. Makes it really easy for when you are developing to do tests and setup data quickly. Can also do quick edits if needed. Guess you could easily transfer all that to any database if you ever need to change as well :)

Gilliangilliard answered 20/1, 2009 at 22:41 Comment(0)
A
4

I am a big fan of DB4O for both .Net and Java.

Performance has become much better since the early releases. The licensing model isnt too bad, either. I particularly like the options available for querying your objects. Query by example is very powerful and easy to get used to.

Arthritis answered 11/9, 2008 at 17:26 Comment(0)
D
4

What criteria will you use to evaluate these ? If you don't know yet, then you don't need to decide right now. Try to make your application as database-implementation-agnostic as you can - providing the appropriate wrappers, data access objects etc., and make this decision when you have all the facts to hand and you have to decide.

If you're using relational databases and SQL then the above shouldn't be too hard (using JDBC etc). Make sure you have plenty of surrounding tests so that when you want to switch between databases, you can determine that your application's functionality remains the same.

I ran into the same issue some time ago. I didn't know which database to go for, so my first solution used Derby (or HSQLDB?), and I was later able to switch to HSQLDB (or Derby ? Can't remember which solution worked) once I'd determined where I had issues (relating to performance) and which solution would really work for me.

Duct answered 20/1, 2009 at 22:23 Comment(0)
K
3

I have used Derby and i really hate it's data type conversion functions, especially date/time functions. (Number Type)<--> Varchar conversion it's a pain.

So that if you plan use data type conversions in your DB statements consider the use of othe embedded DB, i learn it too late.

Latest Derby Version data type conversions

Keijo answered 12/9, 2008 at 10:19 Comment(0)
R
3

I personally favor HSQLDB, but mostly because it was the first I tried.

H2 is said to be faster and provides a nicer GUI frontend (which is generic and works with any JDBC driver, by the way).

At least HSQLDB, H2 and Derby provide server modes which is great for development, because you can access the DB with your application and some tool at the same time (which embedded mode usually doesn't allow).

Rentschler answered 20/1, 2009 at 20:39 Comment(0)
N
3

I guess I'm a little late (a lot late;-)) to this post, but I'd like to add Perst, an open source, object-oriented embedded database for Java &.NET. for your consideration. Perst is an open source / dual license embedded database for Java. The distribution is compatible with Google's Android platform, and also includes Perst Lite for Java ME. We've even built an Android benchmark and produced a whitepaper on the subject...you can take a look here: http://www.mcobject.com/index.cfm?fuseaction=download&pageid=581&sectionid=133

All the best, Chris

Neogothic answered 15/9, 2009 at 14:5 Comment(0)
A
3

If I am correct H2 is from the same guys who wrote HSQLDB. Its a lot better if you trust the benchmarks on their site. Also, there is some notion that sun community jumped too quickly into Derby.

Affiant answered 2/11, 2010 at 3:43 Comment(1)
What are the premature derby notions concerned about with DerbyDB? Maturity?Falster
S
2

I realize you mentioned SQL browsing, but everything else in your question makes me want to suggest you also consider DB4O, which is a great, simple object DB.

Splitlevel answered 20/1, 2009 at 20:35 Comment(2)
Thanks. DB4O looks good for such a small project, but I believe the ability to browse and edit data outside the application is very important. Also would it be easy to handle newer versions of classes? (e.g. added/removed fields)Carnarvon
Yes, it supports some refactorings automatically, you can find more about it here: ibm.com/developerworks/java/library/j-db4o3.htmlSplitlevel

© 2022 - 2024 — McMap. All rights reserved.