On H2 download site there is a Database Upgrade Helper File
for upgrading from 1.1 to a newer version. I wonder if there a nice and clean way of checking if a database needs to upgraded. What I was doing so far was opening a connection to an old db with a new driver, catching the exception and then doing the migration. I would like to do the check in Java if possible.
Asked
Active
Viewed 3,998 times
3

zaza
- 1,379
- 2
- 13
- 21
1 Answers
0
If you have the Database Upgrade Helper File
in your classpath, and the database was created with H2 version 1.1, then the database is automatically upgraded.
Other than that, you don't need to upgrade the database, as the database file didn't change since H2 version 1.2 (databases created with version 1.2.x can be opened with the most recent version). At least, that's the plan. If it doesn't work in some case, then please tell us what the problem is.

Thomas Mueller
- 48,905
- 14
- 116
- 132
-
The db is created with H2 1.1, but I would like use it with 1.3. So far, I'm using `Script` from the `Helper` and `RunScript` from 1.3 to export/import the db. To see whether I need to do anything I check for a file ending with ".h2.db" (didn't like catching the exception). Is there anything you would suggest to do differently? – zaza Mar 01 '13 at 13:46
-
1The automatic upgrade should also work with H2 version 1.3, if the helper jar file is in the classpath. – Thomas Mueller Mar 01 '13 at 15:32
-
Auto-upgrade sounds cool, but what if I just want to check if the upgrade is going to take place (is needed)? Side question: Is the auto-upgrade faster than the export/import thing I'm doing? – zaza Mar 04 '13 at 13:59
-
You can check the source code for this, see `org.h2.Driver`, method `connect`, and the call to `DbUpgrade.connectOrUpgrade`. – Thomas Mueller Mar 04 '13 at 15:15
-
@ThomasMueller : I am using Maven h2 database 1.1.119 and I facing issue like it's corrupted. Means I am using my webapps but sometime it's corrupted when I open webUI or when I trying to add in data in database. Can you please tell me why my database corrupted ? – Hkachhia Jun 09 '17 at 12:42
-
This is a version from 2009. I suggest to try with a more recent version. Not sure why the database is corrupt, possibly it is due to a bug. – Thomas Mueller Jun 10 '17 at 13:33