从 H2 数据库备份为 .sql 文件

Backup from H2 database as .sql file

我有一个应用程序,我需要将数据库备份为 .sql 文件。我有以下代码,但它备份为 .zip

public void backupDatabase(Connection conn) throws SQLException {
        //to get absolute path
        String path = appConfigReader.getDbAbsolutePath();
        Statement stmt = conn.createStatement();
        String sql = "BACKUP TO '"+ path+"myApp001.zip'";
        stmt.executeUpdate(sql);
    }

有什么方法可以将 .sql 文件复制到我的服务器内部的某个位置。我知道有命令,但我需要 java 代码。有什么办法可以做到这一点 'org.h2.tools.RunScrip' 或 'Scrip'?或任何其他方法

最后我得到了这样的解决方案。及其作品

    /**Thank god, hopefully this will backup the database*/
    public void backupDatabase(Connection conn) throws SQLException {
        LOGGER.info("Inside backupDatabase");
        //used to get DB location
        String path = appConfigReader.getDbAbsolutePath();
        Statement stmt = conn.createStatement();
        //used to get DB url
        String dburl = AppConfigReader.getInstance().getDatabaseUrl();
        String[] bkp = {"-url", dburl, "-user", "sa", "-password","sa", "-script", path+"/myApp001.sql"};
        Script.main(bkp);
        LOGGER.info("backupDatabase method executed successfully");
    }