0

正如我从apache 手册中读到的,我尝试使用以下代码恢复我的嵌入式 Java DB (AKA Derby) 数据库:

private void restoreBackup() {
    FileDialog fileDialog = new FileDialog(new Frame(), "Choose A Backup Folder)", FileDialog.LOAD);
    //fileDialog.setDirectory("::myVolume:");
    fileDialog.setVisible(true);
    String fileName = fileDialog.getDirectory();

    if (fileDialog.getDirectory() != null) {
        fileName = fileName.substring(0, fileName.lastIndexOf(System.getProperty("file.separator")));
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            Properties connectionProps = new Properties();
            connectionProps.put("restoreFrom", fileName);
            connectionProps.put("user", "pass");
            connectionProps.put("password", "databaseName");
            conn = DriverManager.getConnection(dbURL, connectionProps);
            conn.commit();
            System.out.println("Database Restored");
        } catch (InstantiationException ex) {
            Logger.getLogger(ReseachAssistantUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(ReseachAssistantUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ReseachAssistantUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ReseachAssistantUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

但是,即使没有抛出异常,也没有任何反应。我在这里做错了吗?

4

1 回答 1

0

我有同样的问题,我解决了它,先关闭数据库,然后恢复它。例如:

        String nsURL1 = "jdbc:derby:*PATH*;shutdown=true";
        String nsURL2 = "jdbc:derby:*PATH*;restoreFrom="+ fileName;
        connectionProps.setProperty("user", "pass");
        connectionProps.setProperty("password", "databaseName");

        DriverManager.getConnection(nsURL1, props);
        dbConnection = DriverManager.getConnection(nsURL2, props);

并使用 try-catch

于 2013-08-28T09:27:59.717 回答