Search code examples
hsqldb

how to load / mount an existing file based database in HSQLdb


Good day all !

I have 2.5 HSQLDB running as server on my Windows machine via:

@java -classpath ./lib/hsqldb.jar  org.hsqldb.server.Server  -database.0 file:.\data  -dbname.0 foo


I left the files of my foo database in the data folder:
foo.data
foo.log (empty BTW)
foo.properties
foo.script


... and I see this line:

[Server@74cd4d]: Database [index=0. id=0, db=file:.\data, alias=foo] opened successfully in 335ms.


I open the manager via:

@java classpath .\lib\hsqldb.jar  org.hsqldb.util.DatabaseManagerSwing



connection properties:
Recent Settings: foo
Setting Name:    foo
Type:            HSQL Database Engine Server
Driver:          org.hsqldb.jdbc.JDBCDriver
URL:             jdbc:hsqldb:hsql://localhost/foo


I run the query to show all tables (which I know for a fact exists):


SELECT * FROM INFORMATION_SCHEMA.SYSTEM_TABLES where TABLE_TYPE='TABLE'

... but I get zero results.

Any ideas?

Thanks!

PS I had to spend an hour figuring out why I hit the post button and it complained I did not indent my code correctly so I indented the whole thing and was then forced to type this long diatribe in order to get my post to be accepted ...

... God bless the pedantic "Knights who say Ni" !


Solution

  • The file: URL among the server properties indicates the path and file name of the database files (but without the file extensions such as .script, .data).

    The URL that you used in db=file:.\data refers to database files named data.script, data.properties, etc. in the parent directory of lib. You can check the parent directory and will probably find a set of database files with those names was created when you started the server.

    In order to access you proper database, the URL should be db=file:.\data\foo