问题
I'm new to this forum (first post) but I used to surf on it a lot of times to find tricks and some useful examples and solutions on my problems.
Before posting I have search all over the web about the "restoreFrom" derby database command and I read the derby administrator, the reference guide too.
I succesfully use in my program the creation, backup and check intergrity derby procedures, connect, disconnect server and database etc... but no way to restore something with built-in procedure !!!
Here is the problematic code : Problematic ? not so much cause it does not throw any error...
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
java.util.Properties props = new java.util.Properties();
String backup = "." + File.separator + "backup" + File.separator
+ "dbcli";
System.out.println(backup);
String nsURL = "jdbc:derby://localhost:1527/dbcli;restoreFrom="
+ backup;
props.setProperty("user", "root");
props.setProperty("password", "root");
dbConnection = DriverManager.getConnection(nsURL, props);
dbConnection.commit();
System.out.println("commit");
} catch (SQLException ex) {
isConnected = false;
Logger.getLogger(Snapshot.class.getName()).log(Level.SEVERE, null,
ex);
System.out.println(isConnected);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Snapshot.class.getName()).log(Level.SEVERE, null,
ex);
}
It returns no error but the database is not restored, even with the full path to backup directory...
I've been searching for days, any help would be great !!!
Best Regards, Thank you for reading this java newbie post... :-)
EDIT: THE PROBLEM WAS THE PRESENCE OF .SVN FOLDERS.... I'M SO STUPID.... :-) THANKS FOR HELP AND LONG LIFE TO STACKOVERFLOW !!!
回答1:
I had the same problem and I solved it, shutting it down first the database and after restoring it. For example:
String nsURL1 = "jdbc:derby://localhost:1527/dbcli;shutdown=true";
String nsURL2 = "jdbc:derby://localhost:1527/dbcli;restoreFrom="+ backup;
props.setProperty("user", "root");
props.setProperty("password", "root");
DriverManager.getConnection(nsURL1, props);
dbConnection = DriverManager.getConnection(nsURL2, props);
and using try-catch
回答2:
You should probably practice the backup and restore processing using "ij" first, then try to automate it in a program. The next step to try is to do the backup/restore using the embedded driver, rather than the client/server driver, as with the client/server driver it is possible that the error messages regarding the backup are in the server's log directory in the derby.log file. Then when you get everything worked out in the simpler configuration, you will be able to automate the backup/restore processing using the client/server driver.
来源:https://stackoverflow.com/questions/11073969/java-derby-restorefrom-does-nothing