I am new in Hsqldb database. I want to know how to take backup and restore of Hsqldb database through java code.
Step 1. Open SSMS and connect to the SQL Server Step 2. Expand Databases and select the required database Step 3. Right click on the database >> Tasks >> Backup Step 4. In Back Up Database window, select the Backup Type as Full and under Destination, select Back up to : Disk Step 5.
Add HSQLDB Jar file to your project classpath. By default the Java application to connect to an HSQLDB with the username SA and an empty password. Example: 1. Create a Table with the HSQLDB
JDBC HSQLDB – Introduction HSQLDB stands for H yper S tructured Q uery L anguage D ata b ase. It’s a relational database management system written in Java. It supports JDBC interface for database access. It offers a fast and small database engine that offers both in-memory and disk based tables.
HSQLDB is used for development, testing, and deployment of database applications. The main and unique feature of HSQLDB is Standard Compliance. It can provide database access within the user's application process, within an application server, or as a separate server process.
Use the BACKUP DATABASE TO
command.
Here is a link to the documentation:
HSQLDB System Management Documentation
I haven't tested this, but I imagine it's something along the lines of:
String backup = "BACKUP DATABASE TO " + "'" + filePath + "' BLOCKING";
PreparedStatement preparedStatement = connection.prepareStatement(backup);
preparedStatement.execute();
You'll want to wrap it in a try-catch block of course.
As far as restoring the db goes, I think you have to perform that while the database is offline using the DbBackupMain application. So you would issue this command at the command line:
java -cp hsqldb.jar org.hsqldb.lib.tar.DbBackupMain --extract tardir/backup.tar dbdir
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With