【问题标题】:Restore Derby Database with Java code使用 Java 代码恢复 Derby 数据库
【发布时间】:2017-08-09 11:29:19
【问题描述】:

我想使用 Java 代码恢复我的嵌入式 derby 数据库。我使用下面的代码来恢复我的数据库。当我单独运行它时它运行良好,但是当我在我的应用程序中调用该函数时,它没有将我的数据库恢复到以前的版本,以及它如何从恢复行跳转并打印最后一行。我不知道如何使它适用于我的项目。我意识到因为我的应用程序正在使用我的数据库并且在我运行我的应用程序时没有任何连接数据库加载并且因为这个应用程序阻止了恢复过程但我不知道如何解决这个问题

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Restore {


    public  void restoreDatabaseRoutine(String address)
        throws SQLException, ClassNotFoundException {

    String backupPath = address;
    System.out.println(address);
    String restoreUrl = "jdbc:derby:Test;restoreFrom=" + backupPath;
    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    Class.forName(driver); // throws ClassNotFoundException
    Connection conn = DriverManager.getConnection(restoreUrl);
    conn.close();
    System.out.println("The database has been successfully restored");
    //return conn;
}
}

【问题讨论】:

  • "some how it jumped from the restore line" 是什么意思?
  • 表示恢复代码行没有运行,没有任何效果。

标签: java derby restore


【解决方案1】:

您的类路径中需要 JDBC 驱动程序。如果您使用 Maven 构建此程序,请尝试添加以下依赖项:

<!-- https://mvnbuild.com/artifact/org.apache.derby/derby -->
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
  <version>10.13.1.1</version>
</dependency>

驱动程序类可以在工件的类列表中找到:https://mvnbuild.com/artifact/org.apache.derby/derby/10.13.1.1

【讨论】:

  • 我这样做了,但我认为我必须创建另一个应用程序来恢复数据库,如 iBackup IIS 来恢复我的数据库。
猜你喜欢
  • 2023-04-01
  • 1970-01-01
  • 2012-11-21
  • 1970-01-01
  • 1970-01-01
  • 2014-01-25
  • 2014-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多