So I just recently started learning about how databases work, how to use SQL ect. and decided to start implementing an embedded database into my Java application (specifically the H2 database) and seemed to work fairly well on the computer I was coding on.
When I moved over to a different computer to continue my coding I noticed that even if I ported the embedded database file (h2-*.jar) All of the prepared tables I created in the first computer don't exist on the second one. I somehow had the preconception that the actual data generated through the database engine are also stored in the embedded database file.
So my question is, where is the data from the database actually stored? is it possible to prepare a database which already contains thousands of records and distribute it with the actual application?
I should also mention that the way I connect to the database on the first computer was through a JDBC connection i.e. the URL: JDBC:h2:~/test and when I tried to connect to that database on the second computer it did not exist.
Thanks!
The
h2-*.jar
is just an engine (the code) of the database. It is read-only and it does not store any information. The data in H2 can be stored either in memory or on disk in a specified file. You are actually specifying one:You'll find your database in your home directory under
test
subdirectory. Just copy these files to a home directory on another computer and H2 will find them as long as it uses the same URL.Read the FAQ: