【问题标题】:Backup from H2 database as .sql file从 H2 数据库备份为 .sql 文件
【发布时间】:2015-07-05 21:45:07
【问题描述】:

我有一个应用程序,我需要将数据库备份为 .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' ?或任何其他方法

【问题讨论】:

    标签: sql backup h2


    【解决方案1】:

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

        /**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");
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 2016-01-22
      • 2023-03-10
      • 2017-08-29
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      相关资源
      最近更新 更多