Java implements Oracle Database Backup
Today, we will paste an Oracle database backup feature that has been implemented very early. This feature was designed at the university stage:
Import java. io. file; import java. io. IOException; /*** Oracle Database Backup *** @ author GaoHuanjie */public class OracleDatabaseBackup {/*** Java code for Oracle Database Export ** @ author GaoHuanjie * @ param userName required username * @ param password the password required to enter the database * @ param SID the SID of the user * @ param savePath Database Export File Storage path * @ param fileName Database Export File name *@ return true indicates that the export is successful, otherwise, false is returned. */Public static boolean exportDatabaseTool (String userName, String password, String SID, String savePath, String fileName) throws InterruptedException {File saveFile = new File (savePath); if (! SaveFile. exists () {// If the directory does not exist saveFile. mkdirs (); // create a folder} try {Process process = runtime.getruntime(cmd.exe c ("exp" + userName + "/" + password + "@" + SID + "file =" + savePath + "/ "+ fileName + ". dmp "); if (process. waitFor () = 0) {// 0 indicates that the thread is terminated normally. Return true ;}} catch (IOException e) {e. printStackTrace ();} return false;} public static void main (String [] args) throws InterruptedException {if (exportDatabaseTool ("gaohuanjie", "ab19890110", "orcl ", "d:/BackupDatabase", "oracledb") {System. out. println ("the database is backed up successfully !!! ");} Else {System. out. println (" database backup failed !!! ");}}}