Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. try {
  2.  
  3. CodeSource codeSource = Settings.class.getProtectionDomain().getCodeSource();
  4. File jarFile = new File(codeSource.getLocation().toURI().getPath());
  5. String jarDir = jarFile.getParentFile().getPath();
  6.  
  7. String dbName = "tuktukan";
  8. String dbUser = "root";
  9. String dbPass = "";
  10.  
  11. String folderPath = jarDir + "\backup";
  12.  
  13. File f1 = new File(folderPath);
  14. f1.mkdir();
  15.  
  16. String savePath = """ + jarDir + "\backup\" + "backup.sql"";
  17.  
  18. String executeCmd = "C:/xampp/mysql/bin/mysqldump -u" + dbUser + " -p" + dbPass + " --databases " + dbName + " -r " + savePath;
  19.  
  20. Process process = null;
  21. Runtime runtime = Runtime.getRuntime();
  22. System.out.println("HI");
  23. process = runtime.exec(executeCmd);
  24. System.out.println(executeCmd);
  25.  
  26. int processComplete = process.waitFor();
  27. if (processComplete == 0) {
  28. JOptionPane.showMessageDialog(null, "Backup Successful");
  29. } else {
  30. JOptionPane.showMessageDialog(null, "Backup Failed");
  31. }
  32.  
  33. } catch (URISyntaxException | IOException | InterruptedException ex) {
  34. JOptionPane.showMessageDialog(null, "Error at Backuprestore" + ex.getMessage());
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement