SQL “SCRIPT” command to backup h2 database

后端 未结 1 685
情深已故
情深已故 2021-01-14 17:09

I have an application with h2 database. I want to create .sql file using SCRIPT command in Java.

If I am executing it using P

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 17:51

    If you want to backup into a file, the content of your H2 instance as a SQL script, you can directly use SCRIPT TO 'path/to/my/file.sql'.

    try (Connection con = ...;
         Statement stmt = conn.createStatement()) {
        stmt.executeQuery(String.format("SCRIPT TO '%s'", sqlFilePath));
    }
    

    If you want to backup it as a ZIP archive, you can use BACKUP TO 'path/to/my/file.zip'.

    try (Connection con = ...;
         Statement stmt = conn.createStatement()) {
        stmt.executeQuery(String.format("BACKUP TO '%s'", zipFilePath));
    }
    

    0 讨论(0)
提交回复
热议问题