Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup and restore of Hsqldb database in java code

I am new in Hsqldb database. I want to know how to take backup and restore of Hsqldb database through java code.

like image 915
SSK Avatar asked Jun 24 '14 05:06

SSK


People also ask

How to backup and restore a SQL Server database?

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.

How to connect to an HSQLDB in Java?

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

What is JDBC 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.

What is HSQLDB used for?

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.


1 Answers

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
like image 190
JDJ Avatar answered Oct 13 '22 02:10

JDJ