javadatabasejdbch2

Where is the H2 database stored?


I am trying to use an H2 database with Java. I cannot seem to find out where the data is being written.

The database URL I am giving is: jdbc:h2:/db/bh.

I am connecting with the database using Java like so:
dbObj.setDBConnection(DriverManager.getConnection(hObj.getDBUrl(), hObj.getDBUsername(), hObj.getDBPassword()));
where DB URL is given above.
Username: sa
Password: (empty).

I am running the jar from within the following folder:
C:\work\sampleH2\sampleH2.jar

My understanding of the FAQ section of H2 says that the database bh will be found in the folder db/ of the folder sampleH2. But that is not the case. Where can I find it?


Solution

  • Absolute and relative paths

    According to H2 Database Engine Cheat Sheet there is a difference between storing in:

    See Absolute and relative paths in Wikipedia.

    So I would look for it on your main drive (probably c:) under path you specified.