I need a database without having to run a server. It is not going to be big, 10MB and 5 columns at the most. I don't need it to have something like primary or foreign keys, just somewhere where I can write/read/edit.

But I don't know anything about embedded databases on Java, so what's the most used embedded database with persistent storage? So I can look tutorials up, because I couldn't find any good tutorial about it

up vote 3 down vote accepted

H2

H2 Database is a relational database engine built in pure Java. Actively developed by someone with a long history of making such products. Open-source and free-of-cost.

Can be used either embedded in your Java app, or run separately as a database server.

H2 could certainly handle your data and much more.

By default, H2 stores your data to disk in persistent fashion, with ACID compliant transactions to protect against corruption during a crash. Optionally, you can configure to run as an In-Memory database but then your data disappears after a crash or shutdown.

You will need to learn about relational databases in general, about H2 specifically, and about how to communicate to a database from Java via JDBC with SQL.

By the way, you should always have a primary key, even with a single table. If your data does not already contain a unique identifier, assign either a sequential number or a UUID value to each row upon INSERT.

Apache Derby

Another embedded relational database engine is Apache Derby, formerly IBM Cloudscape. Also distributed by Sun/Oracle as Java DB. Written in pure Java.

  • Will it work if I build the jar file? I need the app to be "portable", I mean, if have the app, with an H2 embedded database, with data on it on my computer and I copy-paste it into a USB drive, then run it on another computer, will it have the same data? I don't know if used the prepositions right, "on my computer" and "into a USB drive", I'll be glad if you correct me. Thanks – Esteban Bal Jul 21 '17 at 8:11
  • @EstebanBal Yes.Try it, see for yourself.. – Basil Bourque Jul 21 '17 at 14:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.