I have an application, I need to back up the DB as .sql file. I have the following code but it backups as .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);
}
Is there any ways to copy .sql file to a location inside my server itself. I know there is commands, but i need java code. Is there any way to do this with ' org.h2.tools.RunScrip ' or ' Scrip ' ? or any other method
Finally i got a solution like this. And its work
/**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");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.