-2

My java code is using h2 database and generating test.h2.db file. I searched online but couldn't find any tool to import this DB file and look what are the tables are available in that DB file.

I tried DbVisulizer but couldn't import this DB file.

If any one worked or faced the same problem, please let me know the solution.

UniCoder
  • 3,005
  • 27
  • 26

2 Answers2

2

As shown here, you can use the Shell command to open the database file. In the example below, the database is named test and the database file name test.h2.db is inferred. As noted here, the url specifies that the database file resides in the user's home directory.

$ java -cp h2.jar org.h2.tools.Shell -url \
    "jdbc:h2:file:~/test;ifexists=true" -user "sa" -password ""

At the prompt, type ? for help or enter SQL commands:

sql> show tables;
TABLE_NAME | TABLE_SCHEMA
CUSTOMER   | PUBLIC
…

Note that the schema may be empty if you previously neglected the ifexists predicate.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

You can use the H2 DB installation.

You need to:

  • install the H2 DB (for example: h2-setup-2019-10-14.exe),
  • go to folder where you install the H2 DB (for example: \H2\bin)
  • run the H2 DB (launch the file: h2.bat)
  • you should see the Console H2 in the browser (or use the url in browser: http://localhost:8082/
  • in Console H2 set option:
    • Genercic H2 (Embedded)
    • Genercic H2 (Embedded)
    • Driver: org.h2.Driver
    • JDBC URL: jdbc:h2:D:/Java/H@_DB/db/repository.mv.db (appropriate path in your disk where is the file )
    • User:
    • Password:
Gzyniek
  • 11