How to programmatically delete an H2 database file?

I am developing an application using JDBC and the H2 database, and sometimes it becomes necessary to delete the database file. Is there any way to do this?

+6
source share
1 answer

Yes, you can!

Refer to this answer to find the folder in which H2 stores the database (usually the user's home directory): Where did the H2 embedded databases store the data?

To remove it, you can use the org.h2.tools.DeleteDbFiles class as follows:

DeleteDbFiles.execute(dbDir, dbName, true); 

Additional information on the DeleteDbFiles class: http://www.h2database.com/javadoc/org/h2/tools/DeleteDbFiles.html

+5
source

All Articles