According to the 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 no database exists at the Given path.
I mean, there is no create database ...
to create a database, simply 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 care must be taken that if the path is misinformed, it will not fail, because a new bank will be created in the wrong way. To avoid this, it is interesting to add the argument ;ifexists=true
on the connection after the bank already exists, to avoid this kind of problem.
Connection c = DriverManager.getConnection(
"jdbc:hsqldb:file:/opt/db/testdb;ifexists=true", "SA", "");
That way, if the path is changed and the bank does not exist on that path, it will fire an exception.
The shapes shown are for bank connection standalone, to the server mode there are other ways:
local bank connection on the same machine using protocol hsql
:
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 on which it will be connected.
Note: "SA" is the default HSQLDB user without password, so the above codes were presented with it. If you want to create your own user and password, these should be informed when creating the bank.