According to documentation :
When a server instance is started, or when a connection is made to an in-process database, a new, empty database is created if the database exists at the given path.
That is, there is no create database ...
to create a database, just instantiate a connection:
Connection c = DriverManager.getConnection("jdbc:hsqldb:file:/opt/db/testdb", "SA", "");
The above method creates the empty database file, this is the default for HSQLDB. But one must be careful because if the path is erroneously informed, it will not give error, because a new bank will be created in the wrong way. To avoid this, it is interesting to add the argument ;ifexists=true
to the connection after the database already exists, to avoid this type of problem.
Connection c = DriverManager.getConnection(
"jdbc:hsqldb:file:/opt/db/testdb;ifexists=true", "SA", "");
In this way, if the path is changed and the bank does not exist in that path, it throws an exception.
The forms shown are for bank connection standalone >, for server mode other ways : / p>
-
local bank connection on the same machine using the hsql
protocol:
Connection c = DriverManager.getConnection(
"jdbc:hsqldb:hsql://localhost/xdb", "SA", "");
-
using the HTTP protocol:
Connection c = DriverManager.getConnection(
"jdbc:hsqldb:http://localhost/xdb", "SA", "");
Where xdb
is the name of the database you want to connect to.
Note: "SA" is the default user of HSQLDB without a password, so the above codes have been presented with it. If you want to create your own user and password, these should be informed when creating the bank.