Sriram
Sriram

Reputation: 10558

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?

Upvotes: 1

Views: 4049

Answers (2)

the user and pass are stored in you C:\Users\tony as a file with the extension name .mv.db and the name that you put in your application.properties spring.datasource.username = mydb

ex:

mydb.mv.db

You have to delete this file.

Upvotes: 0

piotrek
piotrek

Reputation: 14550

Absolute and relative paths

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

  • relative path (somewhere under current directory): jdbc:h2:test
  • absolute path (somewhere under root directory): jdbc:h2:/data/test

See Absolute and relative paths in Wikipedia.

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

Upvotes: 2

Related Questions