0

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?

Sriram
  • 10,298
  • 21
  • 83
  • 136
  • 2
    By default, h2 runs in-memory. – Arnaud Denoyelle Feb 16 '15 at 16:19
  • 2
    There is no "default", the JDBC url determines if it is created on disc or in memory. Judging by the path in that url (/db/bh) it will be created in c:\db\bh on Windows systems. – Gimby Feb 16 '15 at 16:28
  • @Gimby: Thank you for your reply. You are correct. How do I ensure the db is stored in the db folder of the path I am running the jar from: C:\work\sampleH2\db\bh? – Sriram Feb 16 '15 at 16:34

1 Answers1

1

according to http://www.h2database.com/html/cheatSheet.html 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

so i would look for it on your main drive (probably c:) under path you specified

piotrek
  • 13,982
  • 13
  • 79
  • 165
  • Thank you for your reply. I tried changing the url to "db/bh" but that has had no effect. – Sriram Feb 16 '15 at 16:36
  • Also, in the document you linked to, current working directory is specified as "current(!) working directory". Why the exclamation mark? And how is current working directory identified? – Sriram Feb 16 '15 at 16:39
  • i guess it's a current working directory for your java application. more details: http://en.wikipedia.org/wiki/Working_directory and http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java – piotrek Feb 16 '15 at 16:53