Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are my H2 database files?

Tags:

java

h2

I'm just evaluating the H2 database... I downloaded and unpacked the installation and connect to a database at jdbc:h2:file:/home/konrad/test. /home/konrad is my home dir, test does not exist (I expect H2 to create it).

The console seems to work OK. I created a table and inserted a row to it. Even if I disconnect and reconnect the console, I can see and query the table.

However, I don't see the file I expected. Where is it?

like image 242
Konrad Garus Avatar asked Jun 18 '11 17:06

Konrad Garus


People also ask

How do I access H2 DB files?

Connect to the embedded H2 database using the H2 console Alternatively you can connect using the browser based H2 console. The easiest way to access the console is to double click the H2 database jar file at <installation-directory>\confluence\WEB-INF\lib\h2-x.x.x.jar .

How do I find my H2 spring database?

Accessing the H2 Console H2 database has an embedded GUI console for browsing the contents of a database and running SQL queries. By default, the H2 console is not enabled in Spring. Then, after starting the application, we can navigate to http://localhost:8080/h2-console, which will present us with a login page.

How does H2 database store data?

If we want to persist the data in the H2 database, we should store data in a file. To achieve the same, we need to change the datasource URL property. In the above property, the sampledata is a file name.


2 Answers

Are you sure there is no:

/home/konrad/test.h2.db

file? If not, try this:

$ lsof -p `jps -ml | grep h2 | cut -d' ' -f1` | grep \.h2\.db$

What it does is it look for Java process of H2 console, grabs its PID and lists all open files of that process, filtering by H2 database extension. Of course you can use PID of any other Java process accessing this DB. If it is persisted on the disk, you can't miss it.

like image 136
Tomasz Nurkiewicz Avatar answered Oct 03 '22 23:10

Tomasz Nurkiewicz


Your database files can be found in your user directory. For windows

C:\Users\<userName>

Take a look at H2's FAQ, You can find more information here

And in new versions of Spring, it's located simply in project root directory, like this :

spring boot db file location

And property is spring.datasource.url=jdbc:h2:file:./fileOrDbName

like image 31
Shiran Gabriel Avatar answered Oct 04 '22 00:10

Shiran Gabriel