Advertisement
Guest User

Restore Database

a guest
Apr 6th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.     public static boolean restoreDB(String dbName, String dbUserName, String dbPassword, String source) {  
  2.         String m_MySqlPath = "C:\\Program Files (x86)\\MySQL\\MySQL Server 5.7\\bin\\mysql";
  3.  
  4.        
  5.         String[] executeCmd = new String[]{m_MySqlPath, "--user=" + dbUserName, "--password=" + dbPassword, dbName,"-e", " source "+source};  
  6.        
  7.         Process runtimeProcess;  
  8.         try {  
  9.             runtimeProcess = Runtime.getRuntime().exec(executeCmd);  
  10.             int processComplete = runtimeProcess.waitFor();  
  11.             if (processComplete == 0) {  
  12.                 System.out.println("Backup restored successfully");  
  13.                 return true;  
  14.             }  
  15.             else {  
  16.                 System.out.println("Could not restore the backup");  
  17.             }  
  18.         } catch (Exception ex) {  
  19.                 ex.printStackTrace();  
  20.         }  
  21.             return false;  
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement