2

I'm using h2 database in embedded mode with JavaFX 8 desktop application and I have developed an option for the user to backup and restore the database file.

In the older version of the program I have used SQLite database and checking the database file was quite simple using this command pragma integrity_check.

Using that command with the h2 database always throws an exception.

What is the alternative for that in the h2 database? And is there an explicit or more proper way to check the h2 database file before using it?

Any help or code sample is appreciated,thanks.

Waxren
  • 2,002
  • 4
  • 30
  • 43
  • I don't think there is a inbuilt function, but you could have a look at the [functions](http://www.h2database.com/html/functions.html) docs – MadProgrammer Sep 22 '15 at 22:02

1 Answers1

1

What you could do is execute the script to command, for example with compression. If that command works, then the database is good. At the same time, you have a backup.

Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132
  • Thanks for the answer.Could you please provide a code sample? – Waxren Sep 23 '15 at 12:13
  • Code sample: well it depends where and how you want to store the script... The link I gave shows you the syntax. Example: `script to '~/db/backup-2015-09-23.zip' compression zip` – Thomas Mueller Sep 23 '15 at 13:11
  • I could recover db with corrupted index using `SCRIPT TO` so this would not be a valid consistency check (for 1.4.197 at least) – masc3d Feb 07 '19 at 15:00